admin管理员组文章数量:1125547
I am using wordpress and I am facing an issue.
Whenever I made any changes to the themes style.css file.
Everyday after certain hrs. The file gets restored to it's default version automatically.
All my changes gets undone.
i am not using git. I am using Go-Daddy as server provider.
i am using the "twenty-twenty" theme.
What can be the reason for that ?
I am using wordpress and I am facing an issue.
Whenever I made any changes to the themes style.css file.
Everyday after certain hrs. The file gets restored to it's default version automatically.
All my changes gets undone.
i am not using git. I am using Go-Daddy as server provider.
i am using the "twenty-twenty" theme.
What can be the reason for that ?
Share Improve this question edited Feb 1, 2024 at 22:11 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jan 31, 2024 at 15:09 Dhaval JoshiDhaval Joshi 113 bronze badges 4 |2 Answers
Reset to default 3Below is a generic response to help you, but first I want to give you my personal opinions based on my experiences with issues regarding using stylesheets with WordPress.
- I never use the themes generic style.css file due to issues like this and other common issues. Google no longer penalizes you for having extra .css files in your site. I could be wrong but I don't think so.
- I always add a new stylesheet file and add cache busting code that keeps it updated to your latest version. Here is how I do that: First I make sure I have a child theme, if you don't have a child theme then that is your issue. You can also use a custom plugin but the gist is the same, add a new css file (google no longer penalizes you for having extra files in your site) Cache busting is the trick, using cache busting you will always see your new changes. Either create a custom plugin or a child theme and add this to your functions / plugin file:
This is for a custom plugin:
function wpb_custom_addons_scripts() {
$ver = mt_rand(1000, 100000); // version which disables caching of scripts and styles
// $ver = '1.9991'; // version which enables caching of scripts and styles
wp_register_style( 'wpb_addons_style', plugins_url( 'includes/css/style.css', __FILE__ ), array(), $ver );
wp_enqueue_style( 'wpb_addons_style' );
wp_register_script( 'wpb_addons_script', plugins_url( 'includes/js/script.js', __FILE__ ), array('jquery'), $ver );
wp_enqueue_script( 'wpb_addons_script' );
}
add_action( 'wp_enqueue_scripts', 'wpb_custom_addons_scripts' );
This is for a child theme:
function wpb_custom_addons_scripts() {
$ver = mt_rand(1000, 100000); // version which disables caching of scripts and styles
// $ver = '1.9991'; // version which enables caching of scripts and styles
wp_register_style( 'wpb_addons_style', get_stylesheet_directory_uri() . '/includes/css/style.css', array(), $ver );
wp_enqueue_style( 'wpb_addons_style' );
wp_register_script( 'wpb_addons_script', get_stylesheet_directory_uri() . '/includes/js/script.js', array('jquery'), $ver );
wp_enqueue_script( 'wpb_addons_script' );
}
add_action( 'wp_enqueue_scripts', 'wpb_custom_addons_scripts' );
Notice the $ver variable, while it is using mt_rand() your css file is loaded every page load. Great for development. Once you are done developing you can use this: $ver = '1.9991' Then every time you update your code increase your version number so the site uses your new code. That is cache busting.
- If my changes are basic and very little I put my custom css in the custom css section like this:
Access the Customizer:
Log in to your WordPress dashboard. Navigate to "Appearance" on the left sidebar. Click on "Customize" to open the theme customizer.
Locate the Additional CSS Section:
In the theme customizer, scroll down until you find the "Additional CSS" section. Click on it to open the CSS editing area and put your code there.
The issue you're experiencing with your WordPress theme's style.css file reverting to its default version after certain hours could be caused by several factors:
Caching Plugins or Server Caching: If you're using caching plugins like WP Rocket or server-level caching, they might be restoring a cached version of the style.css file. Ensure that your caching settings are correctly configured and try clearing the cache after making changes to the style.css file.
Child Theme: If you're not using a child theme, any updates to the main theme (either automatic or manual) can overwrite your customizations. To avoid this, create and activate a child theme, and make your CSS changes in the child theme's style.css file.
Automatic Theme Updates: If your theme is set to update automatically, it might be replacing your customized style.css file with the default one from the update. You can disable automatic theme updates to prevent this.
Managed WordPress Hosting: Some managed WordPress hosting solutions have features that restore files to a known state for security reasons. Check with your hosting provider if such features are active.
Version Control Systems: If your site is under a version control system like Git, and the deployment process is automated, it might be reverting the style.css file to the version stored in the repository.
Security Plugins: Some security plugins might revert changes to core files (like those of themes) if they perceive them as unauthorized changes.
File Permissions: Incorrect file permissions can sometimes lead to issues where changes are not saved correctly. Ensure that your style.css file has the correct file permissions.
To troubleshoot, you can:
Check your site’s error logs and the server’s error logs for any relevant messages. Temporarily disable caching and security plugins to see if the issue persists. Ensure you're using a child theme for your customizations. Check with your hosting provider for any features or configurations that might cause this behavior. Remember to always back up your site before making changes, especially when troubleshooting issues like this.
Are you using a theme you purchased? If so, your changes will get overwritten anytime that theme is updated. Depending on how the theme was built, it could also be overwriting the CSS file via a .scss file or .js file.
You will need to install a child theme and edit the theme files within that new child theme. You shouldn't edit the parent theme or you will eventually run into the same issue. But you can copy theme files from the parent theme into the child theme and edit them there.
Another option would be to go to Appearance > Customize > Additional CSS to add new CSS.
Hope this helps!!
本文标签: Stylecss file gets restored to default version
版权声明:本文标题:Style.css file gets restored to default version 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736666339a1946682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wordpress.com-hosting
- is this a self-hosted WordPress site, or are you using wordpress.com as your host? If the latter, you'll need to ask their support team about this. – Pat J Commented Jan 31, 2024 at 15:37