Enqueue a file that’s not js or css

You could also look to create a special CSS file that you setup an htaccess rewrite rule for. For example wp-content/yourtheme/custom.css And then add a rule in your htaccess: RewriteEngine On RewriteRule ^/wp-content/yourtheme/custom.css$ /wp-content/yourtheme/styles.php [L] You can then call wp-load inside this styles.php file, do any sort of logic required, before outputting your custom css … Read more

Proper Way to Load stylesheet on Condition

You’ll need to put the if statement around the line that enqueues in the first place. // enqueue styles for child theme function wowdental_enqueue_styles() { // enqueue parent styles wp_enqueue_style(‘Divi’, get_template_directory_uri() .’/style.css’, get_the_time() ); // Flip3d css // flip3d only on home page if( is_home() ) { wp_enqueue_style( ‘flip’, get_stylesheet_directory_uri() . ‘/css/flip.css’, get_the_time() ); } … Read more

dynamic name of the style for wp_enqueue_style

this syntax doesn’t seem right to me. First of all what is ABS_URL? If it’s a constant that you’ve defined earlier, then there is an ‘ missing before /includes/box.css’. The code should look like this: $name=”mystyle”; wp_enqueue_style( $name .’-style’, ABS_URL . ‘/includes/box.css’, false ); It works as it should, the output is: <link rel=”stylesheet” id=’mystyle-style-css’ … Read more

How to register and set http/2 server prefetch for a specific asset?

Support for resource hints in WordPress is done through rel attribute of <link> elements whithin the HTML docuemnt, not with HTTP/2 server push (which uses Link headers in the HTTP response). You can use wp_resource_hints filter to add the URLs you need the prefetch like this: add_filter( ‘wp_resource_hints’, ‘cyb_resource_hints’, 10, 2 ); function cyb_resource_hints( $urls, … Read more

Enqueue style for specific site type

is_tax() and is_404() perhaps? https://codex.wordpress.org/Conditional_Tags UPDATE: I’m sorry my original answer was vague, to elaborate better: You can add conditional tags in a wp_enqueue_scripts hook, choosing to register and enqueue when criteria is met, like so: add_action( ‘wp_enqueue_scripts’, ‘mythemes_scripts’ ); function mythemes_scripts() { if (is_category()) { wp_register_style( ‘categoryStyles’, get_template_directory_uri() . ‘/style-category.css’, array(), // maybe the … Read more

Theme JS is available but theme CSS isn’t

It seems to me best to separate styles, from scripts and other assets. This worked: function my_theme_enqueue_styles() { wp_enqueue_style( ‘parent-style’, get_parent_theme_file_uri() . ‘style.css’ ); } add_action( ‘my_theme_enqueue_styles’, ‘wp_enqueue_styles’ ); function my_theme_enqueue_assets() { wp_enqueue_script( ‘behavior’, get_theme_file_uri( ‘behavior.js’ ), array(), null, true ); } add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_assets’ );

Load custom CSS before admin CSS

By default they should already be loading after the core admin styles. I suspect the CSS isn’t even being loaded because you have an invalid parameter in your wp_enqueue_style() call. Its parameters are the same as wp_enqueue_script(). Where you have 99 is where dependencies are actually defined. So WordPress is looking for 99 to be … Read more

I can’t add CSS with functions.php

Before adding any file you must seperate your header.php file & add wp_head() function in header.php file // Load the theme stylesheets function theme_styles() { // Example of loading a custom css file for homepage just on the homepage wp_register_style( ‘custom’, get_template_directory_uri() . ‘/css/custom.css’ ); if(is_page(‘home’)) { wp_enqueue_style(‘custom’); } // Example of loading a main … Read more

Custom plugin – load enqueue only for this plugin

The WordPress documentation for admin_enqueue_scripts says that you can: function load_custom_wp_admin_style($hook) { // Load only on ?page=mypluginname if($hook != ‘toplevel_page_mypluginname’) { return; } wp_enqueue_style( ‘custom_wp_admin_css’, plugins_url(‘admin-style.css’, __FILE__) ); } add_action( ‘admin_enqueue_scripts’, ‘load_custom_wp_admin_style’ ); Basically, you’re being passed $hook and it should be the value of your page name, which is the name you’ve chosen.