admin管理员组

文章数量:1391951

I am calling my stylesheet styles.css within functions.php. Also adding add_action. But it does not work…

<?php
function myBlog_files() {
wp_enqueue_style('styles', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'myBlog_files');
?>

styles.css is on the same level as functions.php in directory. Do I need to call the function within index.php or elsewhere?

Thanks

I am calling my stylesheet styles.css within functions.php. Also adding add_action. But it does not work…

<?php
function myBlog_files() {
wp_enqueue_style('styles', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'myBlog_files');
?>

styles.css is on the same level as functions.php in directory. Do I need to call the function within index.php or elsewhere?

Thanks

Share Improve this question asked Mar 13, 2020 at 12:30 S.HS.H 1054 bronze badges 5
  • 2 It’s style.css, singular. – Jacob Peattie Commented Mar 13, 2020 at 12:44
  • I called it styles.css – S.H Commented Mar 13, 2020 at 12:50
  • 1 Which is why it isn't working. It needs to be style.css. – Jacob Peattie Commented Mar 13, 2020 at 13:01
  • 2 @S.H if you want to use get_stylesheet_uri it must be style.css, a style.css is a mandatory file in a WP theme anyway. If you want to enqueue a file other than style.css you need to specify it, WP isn't psychic and needs to be told explicitly – Tom J Nowell Commented Mar 13, 2020 at 13:01
  • I did not had a header.php – only an index.php. After including it and "singularized" the stylesheet it worked. – S.H Commented Mar 13, 2020 at 17:07
Add a comment  | 

1 Answer 1

Reset to default 0
  • You can used to below snippet code for enqueue your css
<?php
function myBlog_files() {
wp_enqueue_style('styles', get_template_directory_uri()./style.css);
}
add_action('wp_enqueue_scripts', 'myBlog_files');
?>
  • Add Your custom-style.css in another folder you add in folder name in before custom-style.css

For Example :

wp_enqueue_style('styles', get_template_directory_uri()./folder name/style.css);

Refer link for more knowledge

本文标签: cssStylesheet does not load despite functionsphp