How important is it to enqueue a theme’s stylesheet?

It’s important to enqueue the stylesheet because it will allow child themes the flexibility of dequeueing it as well as allowing it to be listed for dependencies and a multitude of other things. It just generally allows greater flexibility, both for you and for any other developers who interact with your code. It’s also important … Read more

How to load css in the footer [duplicate]

Actually all styles should be placed in header. So WordPress doesn’t have a parameter for doing this in the wp_enqueue_style function, because traditionally all styles were added in the head. Recently, many sites have moved to a system where critical “above the fold” styles are loaded in the head, while other styles are loaded in … Read more

Is it ever okay to include inline CSS in plugins?

TL;DR; Enqueue Using external stylesheet PRO: All your styles are in one spot. PRO: Reduces web page coding. PRO: Easier to maintain the plugin. PRO: Can use hooks to alter location of the file. PRO: Can use hooks to unqueue the file. PRO: Can use minify styles automatically. CON: Might add extra HTTP request (can … Read more

Why wp_register_style() is important while I’m using a complete wp_enqueue_style()? [duplicate]

First of all let’s say that regarding these functions what is valid for styles is exactly valid for scripts, but there are some exceptions to the contrary explained in the answer. Main difference between wp_enqueue_* and respective wp_register_* functions, is that the first adds scripts/styles to the queue, the second prepares scripts/styles to be added. … Read more

Using wp_add_inline_style without a stylesheet

You just need to add the styles directly to the page head. The best way to do this is to use the ‘wp_head’ action hook, assuming you are using a theme that has the hook. Like so: add_action(‘wp_head’, ‘my_custom_styles’, 100); function my_custom_styles() { echo “<style>*{color: red}</style>”; } Check out the WP codex to learn more … Read more

wp enqueue style on specific page templates

If you plan to do a lot of WP development you should bookmark this page: http://codex.wordpress.org/Conditional_Tags The other answer works but the conditional relies upon your page slug (myurl.com/this-is-the-slug) never changing. A more reliable method (IMO), and one that fits this case, would be to use the is_page_template(‘example-template.php’) conditional check instead.

Check if a script/style was enqueued/registered

There is a function called wp_script_is( $handle, $list ). $list can be one of: ‘registered’ — was registered through wp_register_script() ‘queue’ — was enqueued through wp_enqueue_script() ‘done’ — has been printed ‘to_do’ — will be printed Ditto all that for wp_style_is().

How do I dequeue a parent theme’s CSS file?

I want to use @import instead so I can override styles more easily Simply. Don’t. Do. That. You simply jump into the same hook and then deregister/dequeue the styles/scripts and throw in your custom ones. function PREFIX_remove_scripts() { wp_dequeue_style( ‘screen’ ); wp_deregister_style( ‘screen’ ); wp_dequeue_script( ‘site’ ); wp_deregister_script( ‘site’ ); // Now register your styles … Read more

Conditionally Loading JavaScript/CSS for Shortcodes

Based on my own experience, I’ve used a combination of method 1 & 2 – the architecture and footer scripts of 1, and the ‘look-ahead’ technique of 2. For the look-ahead though, I use regex in place of stripos; personal preference, faster, and can check for ‘malformed’ shortcode; preg_match( ‘#\[ *shortcode([^\]])*\]#i’, $content ); If you’re … Read more

Where is the right place to register/enqueue scripts & styles

Why registering and queuing properly matters it should be in time – earlier than script/style is up for being output to page, otherwise it is too late; it should be conditional – otherwise you are loading stuff where you don’t need it and cause performance and functionality issues, for this you need WP environment loaded … Read more