Looking to migrate sites from WP Engine? Get $100 per site (up to $10,000)—Offer ends Dec 31, 2024*.

How to Update Your WordPress Theme While Preserving Custom CSS

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

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 customizations, 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’ve added custom CSS, updating can be tricky. You want to apply updates without losing your customizations or risking issues with your site.

This article will guide you through safely updating themes while keeping custom CSS intact, provide a step-by-step update process, introduce 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 Custom CSS with WordPress Theme Updates

Losing your custom CSS during an update 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.

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. Here’s how:

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 makes 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.

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.

Here’s how to create a child theme and add custom CSS:

  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.

Updating Your Theme 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 into 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 theme.

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 nice 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 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

Buildings and light trails on city street at night
WordPress Tutorials

How to Speed Up WordPress Site Load Time

Whether you’re on a downtown expressway or the information superhighway, no one likes to go slow. There’s not much you can do about the granny in the fast lane doing 30 mph. Fortunately, there are […]