Redirecting WordPress Tag Pages for SEO

Home/Redirecting WordPress Tag Pages for SEO

If, like me, you’ve had the necessity to redirect WordPress tag pages to another page or pages for SEO reasons, you might have found a number of different methods to do this.  It’s actually a relatively simple process, but it’s also one that’s essential to implement correctly to avoid any SEO penalties or shortfalls caused by your methods. You certainly don’t need a web programmer to do this for you.

This is specifically aimed at those of you that might have undertaken a re-tagging process, or don’t want your tag pages indexed by Google.

Finding the correct method to redirect your tag pages isn’t always obvious, and there are conflicting articles that indicate that using Javascript HTTP redirects is a way to do this, but with SEO in mind this is a “no no”.

With that in mind I’ll highlight three ways you can make your tag pages redirect seamlessly via a 301 redirect that won’t negatively affect your Google rank (assuming that the tag pages are a problem for you to begin with).

Redirecting Tag Pages Via a .htaccess Redirect

The server side .htaccess redirect is an effective way of redirecting tag pages, but you have to keep in mind that WordPress has the ability to rewrite your .htaccess file.  This is important to note, just in case you utilise a poorly written plugin that removes your code, or a WordPress core update re-writes it and the changes revert the file to default.  This isn’t a common occurrence, but it’s still a point worth raising.

To redirect your tag pages using RegEx via .htaccess, the following .htaccess code should be used:

RewriteEngine On
RedirectMatch 301 ^/tag/(.*) http://web-programmer.co.uk/

The example above redirects any URLs with the /tag/ structure inherent to the Web Programmer UK domain name. In that example, https://www.warrenchandler.com/tag/web-programmer/ would be redirected to http://web-programmer.co.uk/.

Redirecting Tag Pages Via a Plugin

If the above method scares you somewhat, there’s a great WordPress Redirection plugin that will do the heavy lifting for you. You can find out more about it here, or download it from the WordPress repository.

The same RegEx applies as per the .htaccess method above as you’ll see in the image below.

Redirecting WordPress Tag Pages

Choosing Specific Tags to Redirect

Should you wish to redirect specific tags to a certain page or post but still have the fall back “catch all” tag redirect in place, you can also do this via both methods above. It’s basically all about the order in which they are processed, so you’d need to move a specific page 301 redirect above the “catch all” redirect.

For example:

  1. ^/tag/web-development/(.*) => http://web-programmer.co.uk/web-development/
  2. ^/tag/(.*) => http://web-programmer.co.uk/

Redirecting Tag Pages/Archives With One Post

This method is a little more tricky and involved, and if you’re not a programmer I’d probably avoid it. That said, it’s not overly tricky and involves little more than adding the following code to the bottom of your website theme’s functions.php file.

function web-programmer-tag-redirect_to_post(){
    global $wp_query;
    if( is_archive() && $wp_query->post_count == 1 ){
        the_post();
        $target_post_url = get_permalink();
        wp_redirect( $target_post_url );
    }
} add_action('template_redirect', 'web-programmer-tag-redirect_to_post');

The method above isn’t the same as the first two methods in that it specifically looks for tag archives that have a solitary post and redirects the tag page to that single post, rather than the archive list. I’ve included it for completion and specifically for people who want to modify the way the tag archives work without a total redirection, but it can be easily modified to include all tags.

The above method can also be implemented via the Redirection plugin as mentioned earlier, which should be the chosen method unless you want to get more technical and expand upon it.

2017-05-19T15:48:05+00:00 December 6th, 2013|Web Programming, WordPress|2 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

2 Comments

  1. pronto October 28, 2016 at 12:59 am - Reply

    Thanks for the info. It helped a lot.

  2. Tony B June 7, 2017 at 10:34 am - Reply

    Thanks for this. Was a really helpful post Warren.

Leave A Comment