I’ve seen a lot of themes enqueuing style sheets and scripts incorrectly, either by calling them using the wp_print_styles or wp_head hooks, or just placing wp_enqueue_style() right in the header. The queue system works best when everything is queued at once, not periodically throughout the document. And calling with the wp_print_styles hook in version 3.3 can end up putting your styles on the admin page. So, do it correctly using the proper hook:

Proper Enqueue Hooks

I know the hooks say scripts and not styles, but trust me, it’s what you’re supposed to use for both.

Example Code

function themeslug_enqueue_style() {
	wp_enqueue_style( 'core', 'style.css', false ); 
}

function themeslug_enqueue_script() {
	wp_enqueue_script( 'my-js', 'filename.js', false );
}

add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style', 10 );
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script', 1 );

Sources

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation