Child Theme Style being Enqueued Twice

Love this theme!

I just want to point out a small bug that I found involving the Child Theme being Enqueued Twice.

If you look in the Sparkling theme Functions.php, you will find:

// Add main theme stylesheet
  wp_enqueue_style( 'sparkling-style', get_stylesheet_uri() );

Then in the Sparkling Child Functions.php, you will find:

add_action( 'wp_enqueue_scripts', 'sparkling_enqueue_styles', 15 );
function sparkling_enqueue_styles() {
    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')
    );

Resulting in:
<link rel=‘stylesheet’ id=‘sparkling-style-css’ href=‘http://www.######.com/wp-content/themes/sparkling-child/style.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />
<link rel=‘stylesheet’ id=‘parent-style-css’ href=‘http://www.######.com/wp-content/themes/sparkling/style.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />
<link rel=‘stylesheet’ id=‘child-style-css’ href=‘http://www.######.com/wp-content/themes/sparkling-child/style.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />

As you can see, the sparkling-style-css and child-style-css are pointing to the same file.

My solution:

(In Sparkling Functions.php)

// Add main theme stylesheet
wp_enqueue_style( 'sparkling-style', get_template_directory_uri(). '/style.css' );

(In Sparkling Child Functions.php)

add_action( 'wp_enqueue_scripts', 'sparkling_enqueue_styles', 15 );
function sparkling_enqueue_styles() {
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('sparkling-style')
    );

Hi @rwd789,

I hope you are well today and thank you for your question.

From where have you downloaded the Sparkling Child theme that contains the above code?

When you use child theme then the child theme style.css file gets enqueued automatically so you don’t need to enqueue it.

Also you don’t need to use anything in the Sparkling Functions.php file. Just add the following code in the functions.php file of your child theme to make it work.

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

Best Regards,
Movin

Hi Movin,

Thanks for replying to my topic.

I downloaded the theme from here. I have the original theme file still zipped on my hard drive, and when I unzip it, I navigate to the functions.php file, and it shows what I outlined above. Is it possible that this was changed recently in an update or something?

Here is a public version of the theme on GitHub.

https://github.com/puikinsh/Sparkling

https://github.com/puikinsh/Sparkling/blob/master/functions.php#L223


I just updated my site with what you provided and my child theme style.css is not being enqueued. Here is a portion of the theme’s rendered head. (Note: The child theme is set to active)

<link rel=‘stylesheet’ id=‘parent-style-css’ href=‘http://####.com/wp-content/themes/sparkling/style.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />
<link rel=‘stylesheet’ id=‘sparkling-bootstrap-css’ href=‘http://####.com/wp-content/themes/sparkling/inc/css/bootstrap.min.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />
<link rel=‘stylesheet’ id=‘sparkling-icons-css’ href=’//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css’ type=‘text/css’ media=‘all’ />
<link rel=‘stylesheet’ id=‘sparkling-style-css’ href=‘http://####.com/wp-content/themes/sparkling/style.css?ver=4.2.4’ type=‘text/css’ media=‘all’ />

hi, rwd789,

Here is what I did:
Call wp_dequeu_style() first before calling wp_enqueu_style() for the parent style.

wp_dequeue_style( ‘sparkling-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’)

Good luck.

Hi @rwd789,

To troubleshoot the issue could you please tell me which version of Sparkling theme are you using and also share me your whole child theme by attaching zip file of it here so that i can troubleshoot it?

Please don’t use the themes on your live site from from the github https://github.com/puikinsh/Sparkling the code there may be still in development stage and need further testing.

Please use the latest themes from the following pages which are tested and made publicly available.

https://wordpress.org/themes/author/silkalns/

Regards,
Movin