0

currently I deleted the 'classic' hardcoded main /styles.css from header.php and enqueued it from a wp_enqueue_scripts action. Basically, the loading order in header I currently want (and have) is:

[plugin styles]
[main theme styles]
[page-specific styles]
[jquery]

So my current code is:

add_action('wp_enqueue_scripts', 'add_scripts_and_styles', 11); // 11 so they load after plugins

function add_scripts_and_styles() {

    wp_enqueue_style('main_style','/wp-content/themes/mytheme' . '/style.css');

    // ... do other stuff, load other styles and js files
    // js files are loaded in footer, after plugins

}

It's currently all working fine.

What I want to be sure of, is if it's a good practice to load the main theme styles this way, since usually they're hardcoded into the header before anything else.

But basically, I want to be able to override plugins styles before any javascript is executed, and that's the way I did it.

1 Answer 1

2

...if it's a good practice to load the main theme styles this way, since usually they're hardcoded into the header before anything else.

Long story short, yes. WordPress advocates the enqueue "API" for all assets whenever possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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