How to Update WordPress Themes While Preserving Custom CSS

by on October 24, 2024
Illustration of a paint roller updating a webpage

Ask Your Favorite AI

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

Youโ€™ve just finished customizing your WordPress site, and itโ€™s finally looking exactly how you want, colors on point, layout perfectly polished. But just as youโ€™re ready to show it off, a notification pops up: thereโ€™s a critical security update for your theme.

Now youโ€™re faced with a tough decision: update and risk disrupting your WordPress custom CSS, or skip it and leave your site exposed.

Regularly updating your WordPress theme helps keep your site secure, compatible, and feature-rich. These updates often include security patches, ensure your site works smoothly with the latest WordPress core and plugins, and introduce new features to improve your site’s design and user experience.

However, if you add custom CSS to WordPress, updating your theme can be tricky. You want to apply updates without losing your customizations or risking issues with your site.

This article will guide you through how to update WordPress themes while keeping custom CSS intact, provide a step-by-step update process, introduce WordPress child themes for managing customizations, and explain how Pressableโ€™s features, like staging environments and automatic WordPress updates, support smooth theme management.

The Challenge of Preserving WordPress Custom CSS CSS with Theme Updates

Losing your custom CSS during WordPress theme updates can cause major headaches, leading to design inconsistencies, broken layouts, and a loss of the branding elements that make your site unique. The styles you carefully crafted to improve user experience might vanish, leaving your site looking unpolished and unprofessional.

For your WooCommerce store, this could have a serious impact on your customersโ€™ experience:

  • Custom product displays, like enlarged images on hover, could disappear, reducing customer engagement.
  • Your checkout page might revert to its default styling, creating visual inconsistencies and confusing shoppers.
  • Responsive design tweaks could be lost, leading to misaligned elements and frustrating mobile experiences.

Losing custom CSS could literally mean losing customers. Luckily, as weโ€™ll see in the next section, this is totally avoidable.

Why Do Theme Updates Break WordPress Custom CSS?

When WordPress updates a theme, it replaces the entire theme folder with a fresh copy from the developer. Any WordPress custom CSS you’ve added directly to the theme’s style.css file gets overwritten in the process, because that file is part of what’s being replaced.

CSS stored outside the theme folder survives WordPress theme updates. Styles added through the WordPress dashboard, for example, are saved to the database rather than to theme files, so updates don’t touch them.

How To Update Your WordPress Theme To Preserve Custom CSS

Updating your WordPress theme doesn’t have to mean sacrificing your custom CSS. With the right approach, you can keep your site secure and up-to-date while preserving your unique design. You’ll need to back up your site, use a child theme for customizations, test on a staging site, and update through the dashboard or file transfer.

Back Up Your Website

Before updating your theme, create a comprehensive backup of your entire website.

A complete backup includes your database, theme files, plugins, and uploads. This thorough approach allows for easy rollback if needed, minimizing potential downtime and data loss during the update process.

Premium WordPress hosts, like Pressable, provide daily automated backups that make this process easier. If you need to restore your site, you donโ€™t need to worry. You can do it directly from the dashboard, adding an extra layer of security to your update process.

Remember, a good backup is your best defense against update-related issues. Don’t skip this step.

Ensure Your Customizations Are In a Child Theme

If you’ve been adding custom CSS directly to your theme, it’s time to change tactics. This is where you turn to child themes.

What Is a WordPress 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.

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.

A child theme inherits the parent theme’s functionality and styling while giving you a safe space for customizations. This approach ensures your changes won’t vanish during theme updates.

How to Create a Child Theme in WordPress

  1. Choose a parent theme you want to base your child theme on.
  2. Create a new folder in wp-content/themes/ named “parenttheme-child”.
  3. Create a style.css file in your new child theme folder.
  4. Add the theme information header to style.css:
/*
Theme Name: Parent Theme Child
Theme URI: http://example.com/parent-theme-child/
Description: A child theme of ParentTheme
Author: Your Name
Author URI: http://example.com
Template: parenttheme
Version: 1.0.0
*/
  1. Create a functions.php file in your child theme folder and add the code below to enqueue parent and child stylesheets:
function my_child_theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_child_theme_enqueue_styles' );

  1. Activate your new child theme in the WordPress admin panel under Appearance > Themes.
  2. To add custom CSS, open your child theme’s style.css file and add it after the theme information header.
  3. Save the style.css file and refresh your website to see the changes.

Create a Staging Site To Test the Theme Update

Before you dive into updating your live site, set up a staging environment. A staging site is a private copy of your live website. It’s your testing ground for updates, letting you spot and squash any bugs before they crawl into your actual site.

With a staging site, you can update your theme, test all functionality thoroughly, identify potential conflicts with plugins or custom code, and make sure your custom CSS still works as intended.

Pressable’s WordPress hosting simplifies this process with smart staging environments. You can create a mirror of your live site with just a few clicks, test your updates, and then push the changes live when you’re confident everything works as expected.

Remember, a few minutes spent testing can save you hours of troubleshooting on a live site.

WordPress Theme Updates Through the Dashboard

Now that you’ve set up your staging site, it’s time to update your theme there. Going through the WordPress dashboard is typically the easiest way to do this. Here’s how:

  1. Log into your WordPress admin panel.
  2. Navigate to Appearance > Themes.
  3. Locate your current theme.
  4. Look for an Update Available message with an Update Now link.
  5. Click Update Now to start the process.
  6. WordPress will download and install the latest version of your theme.

This process mirrors what you’d do on your live site, allowing you to test the update in a safe environment. Remember, you’re working on your staging site, so don’t panic if something looks off, that’s exactly why we’re testing first.

Updating Your Theme Through SFTP

Sometimes, the dashboard method isn’t an option. That’s when Secure File Transfer Protocol (SFTP) comes in handy. You might use this method if:

  • Your host restricts automatic updates.
  • You’re updating a premium theme not available in the WordPress repository.
  • The automatic update fails due to server restrictions or timeout issues.
  • You need more control over the update process.

Here’s how to update your theme using SFTP:

  1. Download the latest version of your theme from the developer’s website or WordPress repository.
  2. Extract the theme files on your local computer.
  3. Connect to your website using an SFTP client like FileZilla (you’ll need your SFTP credentials from your hosting provider or hosting dashboard)
  4. Go to the wp-content/themes directory on your server.
  5. Rename your current theme folder (e.g., mytheme_old) as a precaution.
  6. Upload the new theme folder to the themes directory.
  7. Log in to your WordPress dashboard and go to Appearance > Themes.
  8. Activate the updated theme if it’s not already active.

After updating, check that it all works correctly and that your custom CSS is still applied. If you hit any snags, you can easily revert to the old version by renaming the folders.

SFTP gives you more control, but it also requires more care. Double-check each step to ensure a smooth update process.

Testing and Troubleshooting Your WordPress Theme After Updating It

After updating your theme, it’s time to test your site to make sure everything works as expected. Here’s what to focus on:

  • Visual inspection: Start with a careful look at your homepage, posts, and pages. Keep an eye out for any design inconsistencies or elements that seem out of place.
  • Custom CSS check: Verify that your custom styles are still applied correctly. Pay attention to colors, fonts, and layouts that you’ve customized.
  • Responsiveness test: Check how your site looks on different devices. Use your computer, tablet, and smartphone to ensure the design adapts well to various screen sizes.
  • Functionality check: Test all menus, forms, and interactive elements. Make sure they work as they did before the update.
  • Use your browserโ€™s inspector: If something looks off, use your browser’s inspector tool to identify missing or conflicting CSS.

Common issues you might encounter include layout shifts, missing design elements, or broken responsiveness. If you spot any problems, don’t panic. You can often restore lost CSS from your backups or child themes.

Don’t forget to verify compatibility with your essential plugins. Sometimes, theme updates can conflict with certain plugins, so it’s important to check that everything plays nicely together.

Finally, run a basic performance check using a tool like Google PageSpeed Insights. This can help you spot any significant performance drops that might have occurred due to the update.

Once again, thorough testing now can save you from headaches later, so take your time.

Pushing the Update Live

After thorough testing on your staging site, it’s time to push the update to your live site. Choose a low-traffic period to minimize disruption and ensure you have a recent backup ready before proceeding.

To update your live site, go to Appearance > Themes in your WordPress dashboard and activate the updated theme.

Monitor your live site closely after the update, checking key pages and functionality. If any issues arise, be prepared to revert to your backup quickly.

Remember, even with careful preparation, unexpected problems can occur. That’s why having a reliable hosting partner like Pressable is the secret to smooth theme updates. They can provide quick support and help you troubleshoot any issues that may arise during the process.

Adding Your Custom CSS To a New WordPress Theme

Sometimes, you’ll want to switch to a completely new theme that better fits your website’s needs. Here’s how to preserve and transfer your custom CSS:

  1. Check the WordPress Customizer (Appearance > Customize) or your current theme’s settings for a Custom CSS section
  2. Copy all custom CSS you find.
  3. Save it in a separate file on your computer.
  4. In your new theme, go to Appearance > Customize.
  5. Look for an Additional CSS or Custom CSS option.
  6. Paste your saved CSS here.

For more control, you can add CSS via the functions.php file:

  1. Create a file named custom-style.css in your theme directory.
  2. Add your custom CSS to this file.
  3. Open functions.php and add this code to tell WordPress to load your custom CSS file:
function my_custom_styles() {
wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/custom-style.css' );
}
add_action( 'wp_enqueue_scripts', 'my_custom_styles' );

Remember to test these changes on a staging site first. Some CSS may need adjusting to work with your new theme’s structure. Take your time to ensure everything looks and functions as expected before pushing changes live.

Pressable Is Your Partner For Smooth WordPress Theme Updates

Pressable simplifies WordPress theme updates with features designed for safety and efficiency. Our WordPress Cloud platform includes daily automated backups, protecting your site’s data. Smart WordPress staging environments allow risk-free update testing before going live.

With a 100% uptime guarantee SLA, your site remains accessible during updates, while auto-scaling capabilities handle any post-update traffic spikes, ensuring smooth performance.

Should you encounter issues, our expert support team is available 24/7 to assist. By choosing Pressable, you’re gaining a partner committed to keeping your WordPress site updated, secure, and performing at its best.

Ready to experience worry-free WordPress theme updates? Check out Pressable’s pricing plans and take the first step towards a more secure and efficient WordPress site!

Read More Articles in WordPress Tutorials

Illustration of graph paper and other architectural drafting tools
WordPress Tutorials

A Guide to Understanding WordPress Architecture

Millions of websites are powered by WordPress, but few owners make the most of the platform. More often than not, this is due to a lack of know-how. Users who donโ€™t have a basic foundational […]

wordpress custom meta tags
WordPress Tutorials

How to Create Custom Meta Tags for a WordPress Website

Are you trying to create custom meta tags for a WordPress website? Custom meta tags are an essential part of an effective search engine optimization (SEO) strategy. Upon discovering them, search engines will use them […]