admin管理员组

文章数量:1289529

I renamed style.css to my-style.css, but now I am getting an error in WordPress:

"The requested theme does not exist. Stylesheet is missing."

I know the reason for that error, but how can I solve that without changing the stylesheet name again?

I renamed style.css to my-style.css, but now I am getting an error in WordPress:

"The requested theme does not exist. Stylesheet is missing."

I know the reason for that error, but how can I solve that without changing the stylesheet name again?

Share Improve this question edited Jul 9, 2021 at 8:59 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jul 9, 2021 at 6:56 user208353user208353
Add a comment  | 

2 Answers 2

Reset to default 1

Your theme must contain a style.css file, and it needs to have a comment at the top with the theme details.

https://developer.wordpress/themes/basics/main-stylesheet-style-css/

You can not delete style.css and have a functioning theme (at least without hacking WordPress core files). All the theme meta information is written in the style specifically. You can, however register another css file named my-style.css or whatever the name you want.

function my_theme_css() {
    wp_enqueue_style( 'my-style', get_template_directory() . '/my-style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_css' );

Now, your style.css does not have any css so you may want to remove it from your html. You can remove it from your site's <head> using wp_dequeue_style(). But the physical file has to be there in your theme's directory.

add_action('init','_remove_style');

function _remove_style(){

    wp_dequeue_style('style.css'); 
}

本文标签: