The “too many redirects” error is a frustrating issue that can prevent users from accessing your WordPress site. It happens when there is a loop of redirects, causing the server to become overwhelmed and unable to load the page. In this article, we’ll show you how to fix the “too many redirects” error in WordPress using a simple code snippet.

Step 1: Clear Your Browser Cache Before we dive into the solution, let’s first clear the browser cache. Sometimes, this error can be caused by a cached version of your site, so clearing your cache can help resolve the issue. To do this, simply go to your browser settings and clear the cache.

Step 2: Check Your WordPress Settings If clearing the cache didn’t work, the next step is to check your WordPress settings. Specifically, you need to make sure that the URL settings are correct. To do this, go to the WordPress dashboard and click on “Settings” then “General.” Make sure that both the “WordPress Address (URL)” and “Site Address (URL)” fields are correct and match your domain.

Step 3: Add a Code Snippet If your URL settings are correct and you’re still experiencing the “too many redirects” error, you can try adding a code snippet to your WordPress site’s functions.php file. This code snippet will redirect all traffic to the non-www version of your site, which can help resolve the error. Here’s the code:

if (isset($_SERVER[‘HTTP_HOST’]) && $_SERVER[‘HTTP_HOST’] != ‘localhost’ && preg_match(‘/^www\.(.*)$/’, $_SERVER[‘HTTP_HOST’], $matches)) {
wp_redirect(“https://” . $matches[1] . $_SERVER[‘REQUEST_URI’], 301);

To add this code snippet, go to the WordPress dashboard and click on “Appearance” then “Theme Editor.” From here, click on the “functions.php” file and add the code snippet at the bottom of the file. Save the changes, and the “too many redirects” error should be resolved.

Conclusion: The “too many redirects” error can be frustrating, but with these simple steps, you can quickly resolve the issue and get your WordPress site back up and running. If you’re still experiencing the error after following these steps, it may be worth contacting your web host for further assistance.

Fixing Broken Images Links after a WordPress Migration