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.

How can I get this child theme stylesheet to properly load? Or if it is correct, why doesn’t my child theme appearance match the parent?

I think you need to declare the bootstrap dependency when you enqueue the parent stylesheet (bootstrap.css is enqueued by the parent theme). The parent theme doesn’t declare the dependency but enqueues style.css after bootstrap.css, so it “just” works. But when you change the order of the enqueue, the dependencies are broken. Use the third parameter … Read more

enqueing Javascript and CSS

If you care about pagespeed and those standards, you should make the resources local instead of off remote servers. Although they’re all off CDNs, nothing’s faster than local. With http/2 on the rise, its going to become less and less important to have fewer scripts- but having them locally will still matter. You can combine … Read more

Enqueueing styles with version variable

Try this // global theme version $version = ‘1.0.0’; function frontend_styles() { global $version; wp_enqueue_style( ‘frontend_styles’, //reference get_stylesheet_directory_uri() . ‘/assets/css/app.min.css’, //source array(), //dependenices $version, //version number ‘all’ //media type (‘all’, ‘screen’, ‘handheld’, ‘print’) ); }

Apply function only if end of url has /amp/ [closed]

In your example, $_SERVER[‘REQUEST_URI’] would return /category/post-slug/amp/ which is not the same as get_permalink($post->ID) which would return https://example.com/category/post-slug/ There are lots of ways to go about this, but one easy one that comes to mind is… if ( strpos($_SERVER[‘REQUEST_URI’], ‘/amp/’ ) !== false ) { The strpos() PHP function finds the position of 2nd string … Read more