0

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

5
  • 2
    It’s style.css, singular. 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. 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

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.