Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Marco Goldin
Marco Goldin
7,913 Points

Stylesheet enqueueing in child-theme doesn't work

Hi, i'm wondering why enqueueing a js file in my child-theme works:

<php ? add_action( 'wp_enqueue_scripts', 'child_add_scripts' );
function child_add_scripts() {
    wp_register_script('stepAssociati',get_stylesheet_directory_uri() . '/js/jquery.steps.js',
        false,'1.0',true);
    wp_enqueue_script( 'stepAssociati' );}
?>

but it doesn't work for css file:

<php ? add_action( 'wp_enqueue_style', 'child_add_styles' );
function child_add_styles() {
    wp_register_style(
        'jquery.steps',
        get_stylesheet_directory_uri() . '/css/jquery.steps.css');
    wp_enqueue_style( 'jquery.steps' );} 
?>

url: http://tropicodellibro.it

2 Answers

Stanley Thijssen
Stanley Thijssen
22,831 Points

Hi Marco,

You are using the wrong action hook for your style enqueue. You are using wp_enqueue_style but it should be wp_enqueue_scripts.

<?php add_action( 'wp_enqueue_scripts', 'child_add_styles' ); ?>
Marco Goldin
Marco Goldin
7,913 Points

thank you, i've been trying that a lot, but it didn't work, and as far as i know wp_enqueue_style is much safer when adding stylesheet file.

Stanley Thijssen
Stanley Thijssen
22,831 Points

As far as I know there is no hook called wp_enqueue_style. your function should really be hooked into wp_enqueue_scripts instead and it should work fine. You also wrote your php block wrong should be <?php starting

Marco Goldin
Marco Goldin
7,913 Points

great, thanks! You were right, it was because of the wrong php. I also found that to use the wp_enqueue_style function it should be added on the wp_enqueue_scripts action.

Stanley Thijssen
Stanley Thijssen
22,831 Points

Nice! Can you close the topic?:)