1

I have create child theme with style.css and functions.css, I edit parts style.css in child theme to get best style. But some page have no effect and style.css from child theme repeated with another version.

style.css

#masthead {
    top: 0px;
    background: black !important;
    border-top: 2px solid rgba(250,105, 0, 1);
    border-bottom: 2px solid rgba(250,105,0, 1);
}

functions.php

<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style';

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

child theme style.css repeated

1

I think you can try this :

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
?>

Just try it. i hope is useful.

0

When developing a child theme the wordpress environment will automatically load the style.css file inside the child theme folder. Thus it is only needed to enqueue the parent style in your functions.php fil

add_action('wp_enqueue_scripts', 'enqueue_parent_styles' );

function enqueue_parent_styles() {
   wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

Trying to enqueue the style sheet from the child theme here as well will result in wordpress loading the child style.css file twice.

  • so the code just load parent style and then child style will load automatic? – ahmadbagwi Mar 3 '17 at 6:55
  • yeah from what I have seen in the past. Even though the official developers guide for child themes on WP says that you should load a child style sheet as well WP will load your child style twice when you do that. – marwyk87 Mar 3 '17 at 7:06
0

What you miss is that in your functions.php codesnippet above you failed to name your own parent style.

In the code you posted in the 4th line from above need customization according to the name of your actual parent style. So as an example this line:

$parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

should look like this in case of using Divi:

$parent_style = 'divi-style'; // This is 'divi-style' for the Divi theme.

To find out what you should put there instead of 'parent-style' in your case, go to your parent theme folder and open the original (or now parent) functions.php, and there search for "wp_enqueue_style". You will find something like this:

wp_enqueue_style( 'divi-style', get_stylesheet_uri(), array(), $theme_version );

This is in my case where I use Divi theme. Look at the first attribute of the function. That's what you need. An other example: In case Twenty Fifteen the first attribute will be: 'twentyfifteen-style'

So once you found the used tag-name for your parent style update your 4th line accordingly.

Hope it helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.