Header Child Theme, what to put in?

Home Forums Premium Themes Support Forum Responsive II (Responsive Mobile) Header Child Theme, what to put in?

This topic contains 3 replies, has 2 voices, and was last updated by  Milind (CyberChimps Team) 1 week ago.

  • Author
    Posts
  • #268570

    henk2
    Participant

    I’m a little confused about the start of a child theme. I want to avoid duplicate loading and loading the child theme above the parent to overrule some things.
    I just had the header as described in https://codex.wordpress.org/Child_Themes .
    I did not have the extra php code to load the child after the parent as described there. I did this for one function because there was no effect. Therefore I looked again in the wordpress advise codex.

    This recommended start of the functions.php is my interpretation for my child theme (xy-responsive) of the parent theme:

    add_action( 'wp_enqueue_scripts', 'xy_responsive_theme_enqueue_styles' );
    function xy_responsive_theme_enqueue_styles() {
        $parent_style = 'responsive-mobile'; 
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/about.css' );
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/style.css' );
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/style.min.css' );
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/style-rtl.css' );
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/css/style-rtl.min.css' );
    
        wp_enqueue_style( 'xy-responsive',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }

    I saw that in /responsive-mobile/includes/functions.php a function is on line 152, ‘responsive_mobile_css()’. That seems overlapping my function. I’m also not sure that all css of the parent theme is included; how to be sure if an extra css is added to the parent?

    Please give a hint for the header php in the child theme.

  • #268580

    Hi,

    You can follow the steps provided in the link to create a child theme. Just create a style.css file in the child theme to get the child theme to work.
    When you create a child theme and install it, it will look exactly as the parent theme. you can do changes in the child theme which then will be reflected on the site.

    If you want to override the header file from the parent theme, just copy the header.php file from the parent theme and paste it in the child theme folder.
    To check if it’s working, simply add any content in the header.php file added in the child theme. Save the changes and it should be reflected in on your site.

    Hope this helps.
    Thank you.

  • #268607

    henk2
    Participant

    Oke.
    Without the WordPress recommended start in functions.php it seems to work. Alternative pages work also.
    I had the @import to include the parent theme. That method should be changed according WordPress. So I tried the WordPress advise. In my child are various functions in addition tho the parent.
    But even without the @import and function as described on the WordPress site, things seem to work.
    This is why I tried to find out why? Is this WordPress instruction worthless?

  • #268625

    Hi,

    The instruction provided by WordPress for creating a child theme is correct. The function.php file is used for including some extra functions in the child theme or modify the function from the parent theme.
    The child theme should work only with the style.css file i.e. rest all other content is taken from the parent theme.

    The child theme works in the following way.
    1. If you want to override the header.php file in your child theme, please copy the header.php file from the parent theme and then paste in the child theme folder.
    2. When the child theme is activated, to load a header, it will first look for the header file in the child theme. if the header.php file exists in the child theme it will load the content from it.
    3. If the header.php file doesn’t exist in the child theme folder, it will search for it in the parent theme folder and load it from there.

    Hence, the child theme first looks for the code or function or file in its own directory.

You must be logged in to reply to this topic.