简体   繁体   中英

Css not enqueueing with get_template_directory_uri()

I'm having trouble calling my stylesheets using the enqueueing method on my functions.php file. I'm using the following

<?php

function load_stylesheets()
{
    wp_register_style('style', get_template_directory_uri() . 
    '/style.css', array(), false, 'all');
    wp_enqueue_syle('style');
}
    add_action('wp_enqueue_scripts', 'load_stylesheets');
?>

I'm guessing that this is a hierarchy problem as I don't see any problem code wise. I have a theme folder with all of my php files which also contains the css file I'm attempting to reference

Spelling mistake

wp_enqueue_syle('style');

should be wp_enqueue_style('style');

Forgot the 't' :)

Also while I am here...if you are registering then immediately enqueuing (with defaults) you can just do this as they can accept the same args:

wp_enqueue_style('main-style', get_template_directory_uri() . '/style.css');

If you are working on Child Theme you should use, get_stylesheet_directory_uri() instead of get_stylesheet_directory_uri()

// This will point to style.css in child theme
wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );

// This will point to style.css in the parent theme
wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM