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

setting $deps in wordpress function wp_enqueue_style

Hi,

So hopefully some can help me I'm having a problem where one stylesheet is loading before another. And I am trying to set a dependency on my stylesheet but I keep breaking the function when I try and set it. Below is the function that is meant to re-order the css and I want cg-commercegurus to load before cg-child-styles.

// Reorder parent css
function cg_reorder_child_css() {
    wp_dequeue_style( 'cg-style' );
    wp_register_style( 'cg-child-styles', get_stylesheet_uri() );
    wp_enqueue_style( 'cg-commercegurus' );
    wp_enqueue_style( 'cg-responsive' );
    wp_enqueue_style( 'cg-child-styles', 'false' , 'cg-commercegurus' );
}

add_action( 'wp_enqueue_scripts', 'cg_reorder_child_css', 101 );

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

$deps in wp_enqueue_style have to be set in an array. You are setting it as a string. Try changing your $deps parameter to array( 'cg-commercegurus' )

https://codex.wordpress.org/Function_Reference/wp_enqueue_style