CSS file not registering through add_action

The primary issue is an incorrect template conditional tag: if( is_page( ‘home’ ) ) {} This returns true if the current context is a static page, with the slug home. I presume that you’re actually wanting to test for the Site Front Page – in which case you need to use the is_front_page() conditional: if … Read more

Hook after wp_enqueue_scripts

You can hook into wp_enqueue_scripts very late, using the priority argument of add_action. For example: function hook_really_late() { echo ‘Should reasonably be last’; } add_action(‘wp_enqueue_scripts’,’hook_really_late’,PHP_INT_MAX); PHP_INT_MAX should be the highest number assignable as a priority. It is possible that some other code uses the same trick though. That is still probably what I’d recommend. If … Read more

How to enqueue stylesheets?

Please edit the path for the style sheet And put the code in functions.php function my_theme_scripts() { wp_enqueue_style(‘style’, get_stylesheet_directory_uri() . ‘/css/style.css’,false,’all’ ); } add_action( ‘wp_enqueue_scripts’, ‘my_theme_scripts’ );

Optimizing WordPress’s styles and scripts

Query Monitor will show you what is loaded or you can print them directly. function print_wp_scripts_queue(){ $scripts = wp_scripts(); echo “<pre><h1>scripts</h1>”; print_r ( $scripts->queue ); echo “<h1>todo</h1>”; print_r ( $scripts->to_do ); echo “<h1>done</h1>”; print_r ( $scripts->done ); echo “<h1>registered</h1>”; print_r ( $scripts->registered ); echo “</pre>”; wp_die(); } add_action( ‘wp_head’, ‘print_wp_scripts_queue’, PHP_INT_MAX ); wp_deregister_script removes a … Read more

My style in my child theme loads after the parent theme, but it breaks stuff: How do I load it before the parent theme?

How do I load it before the parent theme? I think you are doing it right. If the parent theme is attaching the function responsible for enqueueing its styles to the wp_enqueue_scripts hook, then your bla_enqueue_child_theme_styles() function must be being executed first (because you passed -20 as priority) and your styles should be being included … Read more

Override load-styles.php with admin screen css

If its just that one style you want to edit, you could try… add_action(‘admin_head’, ‘admin_styles’); function admin_styles() { echo ‘<style> #poststuff #post-body.columns-2 { margin-right: 300px; dispay:flex important; flex-direction:column !important; } </style>’; } Or add a separate stylesheet with something like this… add_action(‘admin_head’, ‘admin_styles’); function admin_styles() { echo ‘<link rel=”stylesheet” href=”https://wordpress.stackexchange.com/questions/314539/style.css” type=”text/css” media=”all” />’; }

How to link style.css in functions.php

To get this working: (1) Your index.php file should begin with: <?php get_header(); ?> and end with: <?php get_footer(); ?> (2) Your header.php file should have the following right before the closing </head> tag: <?php wp_head(); ?> Note: header.php also has other things, but I am assuming you have them set up already. (3) Your … Read more

If is multiple page templates

I you want the script be enqueued on page-index.php and page-contact-us.php, then you must check that that page templates are used but you are checking if they are not used. Chagne this: if ( !is_page_template(‘page-templates/page-index.php’) && !is_page_template(‘page-templates/page-contact-us.php’) ) { with: if ( is_page_template(‘page-templates/page-index.php’) || is_page_template(‘page-templates/page-contact-us.php’) ) { The first code reads like: if is NOT … Read more