Contents
How to select which stylesheet to enqueue?
In order to select which stylesheet will be loaded, you simply add your logic to your add_my_stylesheet () function; if you don’t wish for a stylesheet to be used, then you don’t enqueue it, i.e.: related to the admin option. That way it’ll only pull the CSS that you want on the desired page / when the desired admin option is selected.
Where do I print an enqueued stylesheet in WordPress?
You don’t need to “call” an enqueued stylesheet as you suggested – if it is enqueued, then it will be printed out in an HTML element in the section in the same manner that WordPress loads it’s own stylesheets.
How to use WP enqueue style in WordPress?
The calls to wp_enqueue_style () then add the specified stylesheets to a list of stylesheets that will be loaded (if you specify the dependencies argument, then WordPress will also take care of making sure that your stylesheets load in the correct order).
Which is admin print styles or admin enqueue styles?
Confusingly, the practice of using the admin_print_styles and admin_enqueue_styles actions to enqueue stylesheets is incorrect – as counter-intuitive as it is, you should use admin_enqueue_scripts instead.
How to correctly enqueue stylesheets and script files in WordPress?
The first parameter tells WordPress when to call the function, and for this, we are going to use wp_enqueue_scripts. Again, we need to place this within the brackets and within single quotation marks. The second parameter tells WordPress which function to call.
Where does the stylesheet go in a theme?
If the stylesheet is in a folder within the theme files then you will need to include this folder name too. For example, your stylesheet might be in a folder called css, so this is how you would enqueue that file: And that’s how we enqueue a stylesheet that isn’t the main stylesheet of a theme.
How to use conditional content in WP enqueue?
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.
Is it safe to enqueue a stylesheet in WordPress?
A safe way to add/enqueue a stylesheet file to the WordPress generated page. If you are going to use some jQuery UI features you might have to provide your own CSS file: WordPress core does not have a full jQuery UI theme! Default styles that are loaded via WordPress Core can be discerned via the source code on the default styles page.