Stylesheet not linking

get_template_directory_uri() just returns the directory of the current theme, not the link to the actual stylesheet. In functions.php try: function register_directories_style() { wp_register_style(‘style’, get_template_directory_uri().’/style.css’, [], 1); wp_enqueue_style(‘style’); } add_action( ‘wp_enqueue_scripts’, ‘register_directories_style’); if you wanted to select a different stylesheet, you just updated the $src arguement. e.g. function register_directories_style() { wp_register_style(‘directory_style’, get_template_directory_uri().’/css/directories.css’, [], 1); wp_enqueue_style(‘directory_style’); } … Read more

Use wp_add_inline_style to add code to before wp_head?

Yes, that should be doable. Just enqueue your inline styles with callback hooked to wp_enqueue_scripts and priority set to 0 (assuming other styles are loader later / lower priority / bigger number). You also need to register a dummy handle to which you attach the inline styles to, so no other styles are loaded before … Read more

How to make wp_enqueue_style and wp_enqueue_script work only on custom post type

You can use conditionals: <?php add_action( ‘wp_enqueue_scripts’, ‘wpse_enqueues’ ); function wpse_enqueues() { // Only enqueue on specified single CPTs if( is_singular( array( ‘anime’, ‘manga’ ) ) ) { wp_enqueue_style( ‘wp-manga-plugin-css’, WP_MANGA_URI . ‘assets/css/style.css’ ); } } ?> If you need the CSS on archives as well, that’s another condition: if( is_singular( array( ‘anime’, ‘manga’ ) … Read more

Enqueue scripts not working with if is page conditional tag in functions.php

Try doing in the opposite way. Add_action can always be active, and add the if statement into the function. Like this: add_action(‘wp_enqueue_scripts’, ‘insert_mapsvg_scripts’); function insert_mapsvg_scripts() { if( is_page( 37629 ) ) { wp_enqueue_style( ‘mapsvg_css’, site_url(‘/mapsvg/css/mapsvg.css’) ); wp_enqueue_style( ‘nanoscroller_css’, site_url(‘/mapsvg/css/nanoscroller.css’) ); wp_enqueue_script( ‘mousewheel_js’, site_url(‘/mapsvg/js/jquery.mousewheel.min.js’), array(‘jquery’), ”, true ); wp_enqueue_script( ‘nanoscroller_js’, site_url(‘/mapsvg/js/jquery.nanoscroller.min.js’), array(‘jquery’), ”, true ); wp_enqueue_script( … Read more

Loading different stylesheet on WordPress pages?

Don’t use a shortcode for wp_enqueue_style(); it won’t do any good, because by the time the shortcode is parsed, all the relevant hooks ( wp_head, wp_print_styles) will have already fired. Write a function, in functions.php, to enqueue different style sheets based on is_page( $id ) (where $id can be an ID, slug, or title). Then … Read more

How can I let templates choose which stylesheets are enqueued?

Check the current template in your callback. This is a post meta field named _wp_page_template. add_action(“wp_enqueue_scripts”, function() { // This stylesheet is used on *every* page wp_register_style(“sitewide”, get_template_directory_uri() . “/assets/sitewide.css”); wp_enqueue_style(“sitewide”); if ( ! is_singular() ) return; $template = get_post_meta( get_the_ID(), ‘_wp_page_template’, TRUE ); // now enqueue further stylesheets depending on the current template });

Prevent a base themes css file from loading

You can use wp_deregister_style in your child theme. Like this. function remove_unwanted_css() { wp_dequeue_style( ‘bootstrap’ ); wp_deregister_style( ‘bootstrap’ ); wp_dequeue_style( ‘bootstrap-custom’ ); wp_deregister_style( ‘bootstrap-custom’ ); } add_action( ‘wp_enqueue_scripts’, ‘remove_unwanted_css’, 20 ); Similarly you can deregister other unwanted css too. Just add wp_deregister_style in this function.

@font-face broken in child theme

The problem is not there in your @font-face it’s actually in the functions.php where you enqueued the stylesheets. What I assume your parent theme is enqueuing stylesheets like below: <link rel=”stylesheet” id=’bootstrap-css’ href=”http://example.com/wp-content/themes/parenttheme/bootstrap.min.css” type=”text/css” media=”all” /> <link rel=”stylesheet” id=’style-css’ href=”http://example.com/wp-content/themes/parenttheme/style.css” type=”text/css” media=”all” /> But what’s happening in your child theme: <link rel=”stylesheet” id=’parent-style-css’ href=”http://example.com/wp-content/themes/parenttheme/style.css” type=”text/css” … Read more