How to Clear Cache In WordPress Without A Plugin?

18 minutes read

To clear cache in WordPress without using a plugin, you can follow these steps:

  1. Clearing Browser Cache: If you want to clear cache only for yourself and your website visitors, you can try clearing the browser cache. Simply press Ctrl + Shift + R (Windows) or Cmd + Shift + R (Mac) to refresh the page and clear the cache.
  2. Clearing Cache via wp-config.php File: Access your website's files through an FTP client or cPanel's File Manager. Locate the wp-config.php file in the root directory of your WordPress installation. Download a backup of the wp-config.php file for safety. Open the wp-config.php file in a text editor. Add the following lines of code just before the line that says 'That's all, stop editing! Happy blogging.': define('WP_CACHE', true); define('WP_CACHE_KEY_SALT', 'example.com'); // Replace 'example.com' with your domain name. Save the wp-config.php file and upload it back to the server, replacing the existing file. This code enables the built-in WordPress caching system.
  3. Clearing Object Cache: By default, WordPress stores some data in its object cache to speed up performance. To clear the object cache, you need to add the following code to your theme's functions.php file or create a new .php file in the wp-content/mu-plugins directory: global $wpdb; $wpdb->query('DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "%_transient_%";'); $wpdb->query('DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "%_site_transient_%";'); Save the file and upload it to the server.
  4. Clearing Content Delivery Network (CDN) Cache: If you are using a CDN like Cloudflare, follow the instructions provided by your CDN provider to clear the cache.


It's important to note that manually clearing the cache may not be as efficient or comprehensive as using a reliable caching plugin. However, if you don't want to rely on a plugin, these steps should help you clear the cache in WordPress.

Best WordPress Books of June 2024

1
WordPress: The Missing Manual: The Book That Should Have Been in the Box

Rating is 5 out of 5

WordPress: The Missing Manual: The Book That Should Have Been in the Box

2
WordPress All-in-One For Dummies

Rating is 4.9 out of 5

WordPress All-in-One For Dummies

3
Professional WordPress: Design and Development

Rating is 4.8 out of 5

Professional WordPress: Design and Development

  • Wrox Press
4
WordPress Plugin Development Cookbook: Create powerful plugins to extend the world's most popular CMS, 2nd Edition

Rating is 4.7 out of 5

WordPress Plugin Development Cookbook: Create powerful plugins to extend the world's most popular CMS, 2nd Edition

5
Wordpress for Beginners: 3 Books in 1- A Comprehensive Beginners Guide+ Tips and Tricks+ Simple, Effective and Advanced Strategies to Build a Beautiful WordPress Website

Rating is 4.6 out of 5

Wordpress for Beginners: 3 Books in 1- A Comprehensive Beginners Guide+ Tips and Tricks+ Simple, Effective and Advanced Strategies to Build a Beautiful WordPress Website

6
WordPress 5 Cookbook: Actionable solutions to common problems when building websites with WordPress

Rating is 4.5 out of 5

WordPress 5 Cookbook: Actionable solutions to common problems when building websites with WordPress

7
WordPress in easy steps

Rating is 4.4 out of 5

WordPress in easy steps

8
WordPress 5 Complete: Build beautiful and feature-rich websites from scratch, 7th Edition

Rating is 4.3 out of 5

WordPress 5 Complete: Build beautiful and feature-rich websites from scratch, 7th Edition

9
Building Web Apps with WordPress: WordPress as an Application Framework

Rating is 4.2 out of 5

Building Web Apps with WordPress: WordPress as an Application Framework

10
1-Hour WordPress 2021: A visual step-by-step guide to building WordPress websites in one hour or less!

Rating is 4.1 out of 5

1-Hour WordPress 2021: A visual step-by-step guide to building WordPress websites in one hour or less!

11
Professional WordPress Plugin Development, 2nd Edition

Rating is 4 out of 5

Professional WordPress Plugin Development, 2nd Edition

12
WordPress For Dummies (For Dummies (Computer/Tech))

Rating is 3.9 out of 5

WordPress For Dummies (For Dummies (Computer/Tech))

How does caching affect website performance?

Caching can greatly improve website performance by reducing the load time and resource consumption on the server. Here's how it works and affects performance:

  1. Reduced server workload: When a user visits a website that uses caching, the server doesn't need to generate the page content from scratch. Instead, it serves a pre-generated static version of the page, which reduces the processing and database queries required. This minimizes the server workload and allows it to handle more concurrent users, leading to faster response times.
  2. Faster page load times: Caching stores the assets (HTML, CSS, JavaScript, images, etc.) on the user's device or in intermediary servers closer to the user's location. This means subsequent visits to the website can retrieve the assets directly from the cache, avoiding the need to download them again from the server. As a result, the page loads faster since the assets are readily available locally.
  3. Improved user experience: Faster load times can significantly enhance the user experience. Users are more likely to stay engaged and satisfied with a website that loads quickly, reducing bounce rates and increasing pageviews. Cached pages also allow users to navigate through the website quickly, as they don't have to wait for each page to load.
  4. Reduced bandwidth usage: Caching reduces the amount of data transferred between the server and the user's device. Since cached assets are stored locally or within intermediary servers, less data needs to be transmitted over the network. This decreases the bandwidth usage, making it more cost-effective for both the website owner and the user.
  5. Handling traffic spikes: Caching can help handle sudden surges in traffic. When a website experiences high traffic, it can overload the server if each request needs to be processed individually. Caching allows the server to serve cached pages quickly, reducing the strain on the server and ensuring a smooth user experience even during peak times.


However, caching can also have some drawbacks. For example, if the cached content becomes outdated, users may not see the latest changes on the website. Therefore, caching mechanisms must be carefully implemented to strike a balance between performance gains and displaying up-to-date content.

Can clearing the cache fix website display or layout issues?

Yes, clearing the cache can often help fix website display or layout issues. When you visit a website, your browser stores various files and data in its cache to help load the site faster during subsequent visits. However, if these cached files become outdated or corrupted, they may cause display or layout problems on the website.


Clearing the cache removes these stored files and forces the browser to download fresh versions of the website's assets. This can resolve issues like missing or distorted images, broken links, CSS styling problems, outdated scripts, or other display/layout inconsistencies.


After clearing the cache, when you revisit the website, the browser fetches the latest files from the server which can resolve any display or layout issues caused by outdated or corrupt cached files.

How can caching impact the performance of dynamic elements on a WordPress website?

Caching can significantly impact the performance of dynamic elements on a WordPress website in both positive and negative ways. Here are a few ways caching can affect dynamic elements:

  1. Improved Performance: Caching static elements like images, CSS, and JavaScript files can enhance website loading speed and reduce server load. This means dynamic elements can load faster as they depend on these static resources.
  2. Reduced Database Queries: Dynamic elements often require database queries to fetch and display the content. Caching can help by storing the results of these queries and serving them directly without hitting the database every time. This reduces server processing time and latency, leading to faster dynamic element loading.
  3. Stale Content: Caching can, at times, serve cached versions of dynamic content that might be outdated. So, if your website frequently updates dynamic elements like user-specific information or real-time data, caching can cause stale content to be displayed until the cache expires or is cleared.
  4. Caching Inconsistencies: When caching is not configured correctly, it may result in inconsistent display of dynamic elements. Different users may see different versions of dynamic content or experience unexpected behaviors due to cached content being served incorrectly.
  5. Cache Invalidation Challenges: Caching dynamic elements requires a careful approach to cache invalidation. When dynamic content is updated, the cache needs to be invalidated to display the new content immediately. However, implementing effective cache invalidation can be complex and resource-intensive.


It's essential to strike a balance between caching static and dynamic elements and employ proper cache management techniques to optimize the performance of both types of content on a WordPress website.

Best WordPress Hosting Providers in June 2024

1
Vultr

Rating is 5 out of 5

Vultr

  • Ultra-fast Intel Core
  • Low Price and High Quality
  • High Performance and Cheap Cloud Dedicated Servers
2
Digital Ocean

Rating is 4.9 out of 5

Digital Ocean

  • Active Digital Community
  • Simple To Use
  • Starting as low as 5$ per month
3
AWS

Rating is 4.8 out of 5

AWS

4
Cloudways

Rating is 4.7 out of 5

Cloudways

Why would someone want to clear the cache without using a plugin?

There can be several reasons why someone would want to clear their cache without using a plugin:

  1. Speed and performance: Clearing the cache can improve the speed and performance of a website by ensuring that users are getting the most up-to-date version of the content. Cached files can sometimes become outdated or corrupted, and clearing the cache ensures that users are seeing the latest changes.
  2. Troubleshooting: Clearing the cache can help resolve certain website issues or inconsistencies. If a website is not displaying changes or updates properly, clearing the cache can often solve the problem by forcing the browser to fetch fresh files.
  3. Development and testing: Developers often need to clear the cache to preview changes made to the website or web application. It allows them to see the immediate effects of any modifications without relying on cached files.
  4. Security: Sometimes, cached files can contain sensitive or private information. Clearing the cache regularly can help mitigate the risk of unauthorized access to such information, especially if shared devices or public computers are used to access the website.
  5. Privacy: Clearing the cache helps to maintain privacy by removing browsing history, login information, and other temporarily stored data. This can prevent others from accessing personal information and provide a cleaner browsing experience.
  6. Compatibility: Some updates in web development frameworks, themes, or plugins may require a cache clear to ensure compatibility and prevent conflicts. This allows the website to properly reflect any changes or updates made to the underlying components.


Overall, clearing the cache without relying on a plugin can be beneficial in terms of website speed, troubleshooting, development, security, privacy, and compatibility.

Are there any code snippets you can use to clear the cache without a plugin?

Yes, you can clear the cache without using a plugin by adding code snippets to your theme's functions.php file. Here are two commonly used methods to achieve this:

  1. Using PHP to clear cache:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
function clear_cache_function() {
    if (function_exists('w3tc_clear_all')) { // If using W3 Total Cache plugin
        w3tc_clear_all();
        echo 'W3 Total Cache cleared.';
    }

    if (function_exists('wp_cache_clear_cache')) { // If using WP Super Cache plugin
        wp_cache_clear_cache();
        echo 'WP Super Cache cleared.';
    }

    if (function_exists('wp_fastest_cache_clear_cache')) { // If using WP Fastest Cache plugin
        wp_fastest_cache_clear_cache();
        echo 'WP Fastest Cache cleared.';
    }
}
add_action('admin_init', 'clear_cache_function');


  1. Using AJAX to clear cache:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
function clear_cache_ajax_callback() {
    if (function_exists('w3tc_clear_all')) { // If using W3 Total Cache plugin
        w3tc_clear_all();
        echo 'W3 Total Cache cleared.';
    }

    if (function_exists('wp_cache_clear_cache')) { // If using WP Super Cache plugin
        wp_cache_clear_cache();
        echo 'WP Super Cache cleared.';
    }

    if (function_exists('wp_fastest_cache_clear_cache')) { // If using WP Fastest Cache plugin
        wp_fastest_cache_clear_cache();
        echo 'WP Fastest Cache cleared.';
    }

    die();
}
add_action('wp_ajax_clear_cache', 'clear_cache_ajax_callback');
add_action('wp_ajax_nopriv_clear_cache', 'clear_cache_ajax_callback');


To clear the cache, you can either load your site's Admin area to trigger the clear_cache_function() or use an AJAX request to trigger clear_cache_ajax_callback().

Facebook Twitter LinkedIn Whatsapp Pocket

Related Posts:

When fixing widespread WordPress errors, one widespread piece of recommendation that you’d typically obtain is to “clear your browser cache”. Because you don’t must clear browser cache for daily web use, most non-techy customers will not be conversant in the m...
Not too long ago, one in all our readers requested us methods to clear cache in WordPress? Your net browser, internet hosting server, and caching plugins can all serve cached content material which may make it tough so that you can see the adjustments you mad...
To create a plugin in WordPress, you can follow the following steps:Set up the plugin file structure: Create a new folder in the 'wp-content/plugins' directory of your WordPress installation. Give it a unique name, preferably related to your plugin&#39...
To make a WordPress site private, you can follow these steps:Install a plugin: There are several plugins available that can help you make your WordPress site private. One popular option is the "WP Private Content Plus" plugin. Activate the plugin: Afte...
To implement a dark mode toggle for a WordPress site, you can follow these steps:Install a dark mode plugin: There are several plugins available that offer dark mode functionality for WordPress. You can search for "dark mode" in the WordPress plugin re...
To create a custom authentication method for the WordPress REST API, you need to follow these steps:Create a custom plugin: Start by creating a new plugin for your custom authentication method. You can create a new folder in the wp-content/plugins/ directory a...