惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
C
Check Point Blog
月光博客
月光博客
L
LangChain Blog
GbyAI
GbyAI

Pressable

Pressable Achieves Secure Hosting Alliance Certification | Pressable How Pressable MCP Is Changing The Game For WordPress Agencies: A Live Breakdown With Matt Medeiros And Phill Clapham | Pressable April Product Update: Navigation, Organization, And Efficiency | Pressable White-Label WordPress Hosting For Profitable Agencies | Pressable A Guide To Client Onboarding For WordPress Agencies| Pressable WordPress Plugin Management For Scalable Agencies | Pressable WordPress Maintenance Contracts For Agencies: A Complete Guide | Pressable 6 Essential SOPs For WordPress Agencies | Pressable Pressable MCP: Control Your WordPress Hosting With AI. | Pressable WordPress Hosting Cost: Pricing Tiers And What To Expect | Pressable WordPress Performance Budgets: Setting And Monitoring Goals | Pressable WordPress Automation With No Code Automation Tools | Pressable Implement Single Sign-On (SSO) In WordPress | Pressable How To Build A Real Estate Site On WordPress | Pressable Headless WordPress Showdown: Next.js Vs Gatsby | Pressable How To Automate White-Label WordPress Hosting With WHMCS | Pressable Developer Toolkit Update: Automation & UI Enhancements | Pressable How To Build A DXP Platform With WordPress How To Boost WordPress Agency Client Retention: 4 Strategies White Label WordPress Admin For Agency Clients Performance Testing For WordPress Agency Client Sites Performance Testing For WordPress: A Framework For Agency Client Sites How To Upload A Video To WordPress | Pressable How To Mitigate The Impact Of AI Scraper Bots On WordPress Sites WooCommerce ERP Integration: Automate Your Back Office WordPress Personalization: How To Display Tailored Content To Visitors | Pressable WooCommerce Conversion Rate Optimization: A Data-Driven Approach How To Price Your Online Course: WordPress Monetization Guide 7 Ecommerce KPIs You Should Be Measuring | Pressable WooCommerce Vs. BigCommerce: Which Is Best For Your Business Needs? | Pressable WooCommerce Performance Troubleshooting: Diagnosing Speed Issues Step-by-Step | Pressable
How To Retain Custom CSS When Updating A WordPress Theme ...
Amanda Nadhir · 2022-05-05 · via Pressable

Retain Custom CSS

Ask Your Favorite AI

Copy the link to a markdown format of this article for ChatGPT, Claude, Gemini, or your favorite AI.

Themes determine the layout and appearance of WordPress websites. Regardless of which theme you go with, you might need to customize it a bit to suit your specific needs.

One way to customize your theme is to use  Cascading Style Sheets (CSS). This popular style sheet language will allow you to change nearly any element of your theme. You can add custom CSS to your theme to specify background colors, change font sizes, create spacing between content, reposition menus, and more. Custom CSS, though, may be deleted the next time you update your theme.

Why Theme Updates Break Custom CSS

All themes have a style.css file. Available in the theme folder, it contains the CSS. When you update your theme, you’ll download a new, different version of it with which to replace the existing version.

Updating your theme will delete the existing style.css file and replace it with a fresh, new style.css file. The new style.css file won’t contain any custom CSS that you might have added previously. You can always add back the deleted custom CSS, but doing so after each theme update can be tedious.

Add to the Customizer

You can retain custom CSS when updating your theme by adding it to the customizer. The customizer is a theme customization tool in the WordPress dashboard. It features an “Additional CSS” field. Rather than adding custom CSS directly to your theme’s style.css, you can add it to this field.

The “Additional CSS” field was introduced in version 4.7 of WordPress to prevent custom CSS from being deleted during theme updates. It doesn’t affect the style.css file, nor does it affect any other files in the theme folder. When you add custom CSS to the customizer via this field, it will be stored in your website’s database. You can then update your theme while keeping the custom CSS.

To access the customizer, click “Appearance” in the WordPress dashboard and choose “Customize.” The “Additional CSS” tab is near the bottom. Clicking this tab will display a field where you can enter custom CSS. Updating your theme will only replace the files in the theme folder. It won’t replace or otherwise affect your website’s database, so the custom CSS will be preserved.

Adding custom CSS to the customizer allows you to preview it. The customizer has a built-in preview feature for all changes. Whether you’re setting new widgets or adding custom CSS, the customizer will reveal what your website will look like. You can then choose to proceed with the customization by clicking “Publish.” If your website doesn’t look right, you can change the customization options before making it live. Regardless, the customizer will show a preview of your website with the custom CSS.

Create a Child Theme

Another solution is to create a child theme. Child themes are essentially copies of other themes that you can customize without fear of losing your changes. They aren’t complete copies. Rather, most child themes consist of just a few basic files, including a style.css file and a functions.php file.

Child themes are designed to inherit the properties of a parent theme. You can use your theme as a parent theme. The child theme will have its own folder, which will contain its own style.css file and functions.php file. The child theme, however, won’t contain an index.php file, a page.php file, a single.php file, or other standard theme files. It will leverage the parent theme for these properties.

Because child themes have their own style.css file, they support custom CSS. More importantly, child themes retain all of their custom CSS when their parent themes are updated. Updating the parent theme won’t affect the child theme’s style.css file. For instructions on how to create a child theme, visit developer.wordpress.org/themes/advanced-topics/child-theme. Alternatively, some premium themes come with a child theme.

For just a few lines of custom CSS, you may want to add it to the customizer. For larger amounts of custom CSS, creating a child theme is probably worth the effort. A child theme will provide you with a separate style.css file that you can customize.

You can even work on the child theme’s style.css file offline, and because it’s a separate file, you’ll have plenty of space for custom CSS. Adding custom CSS to the customizer will restrict you to a small field that’s only accessible online. The customizer offers the benefit of a preview mode, whereas a child theme offers the benefit of a separate style.css file.

Use a Custom CSS Plugin

You can use a custom CSS plugin. The Simple Custom CSS plugin, for instance, does exactly what it sounds like: It allows you to easily add custom CSS to your theme. Custom CSS added to the plugin will override your theme’s own CSS.

Once you’ve activated the Simple Custom CSS plugin, you should see a new “Custom CSS” tab under “Appearance” in the WordPress dashboard. This is where you can add custom CSS. When you update your theme, the custom CSS will be preserved. Updating your theme will replace the theme’s style.css file, but the plugin will override the new style.css file with your custom CSS.

There’s also the Simple Custom CSS and JS plugin, which supports both custom CSS and custom JavaScript. You can use it to create custom CSS that overrides your theme’s own CSS. If you don’t want to mess with creating a child theme, you may want to use a custom CSS plugin. Downloading a custom CSS plugin is an easy way to preserve custom CSS during theme updates.

Conclusion

It’s frustrating when you lose custom CSS after updating a theme. Even if you saved the custom CSS locally to your computer, you’ll have to go back and add it. You can retain your theme’s custom CSS by using the customizer in the WordPress dashboard, creating a child theme or using a custom CSS plugin.

Amanda Nadhir

With over a decade of experience in the tech industry, Amanda's experience demonstrates her sales expertise. Her commitment to building, training, and guiding high-performing teams has been instrumental in driving Pressable's success. Amanda's extensive background in sales and marketing, coupled with her sharp business acumen, has made her an invaluable asset to the tech community. Her ability to identify and foster talent, combined with her passion for developing winning sales strategies, has propelled her to the forefront of the industry. When she's not expertly navigating the tech sales landscape, she loves spending quality time with her family, loves travel and adventure, lounging pool/beach-side, playing tennis, working out, and meeting people/making friends all along the way!