WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently deleted a large number of tags (~20k-25k) from one of the categories that publishes news items. These tags were contributed by our authors and added no value to the site. As a result, Google's bot is now noticing a LARGE number of 404 errors (~90k) on our site and as a results has pushed our rankings down. Though Google says that 404 errors don't affect, our observation is bit different.

After experiencing the downwards traffic for over a month now, I've decided to redirect all the 404 pages originating from the deleted tags to home-page permanently. I'm not sure whether this is a right step; but that seems to be the only option that I have.

My requirements:

For every 404 resulted on domain.com/tag/ , I want to setup 301 redirect to home page.

I'm a complete noob when it comes to redirects and can't take chances on messing up with these.

share|improve this question

Sounds like an easy task to do. I think hooking into 'template_redirect' and conditionally triggering redirect is the way to go.

EDIT: Seems is_tag() isn't reliable once 404 is triggered. That's why we need to look into the query vars to figure out if it's really a tag query or not.

function redirect_404_tags_wpse67077() {
    global $wp;
    if ( ! empty( $wp->query_vars['tag'] ) && is_404() ) {
        wp_safe_redirect( home_url('/'), 301 );

add_action( 'template_redirect', 'redirect_404_tags_wpse67077', 1 );
share|improve this answer
Where should I add that code? In the functions.php under currently active wordpress theme? – TheBigK Oct 4 '12 at 10:03
Yep, that should do it – Zlatev Oct 4 '12 at 12:53
Doesn't seem to work. I added it to the functions.php under the active theme folder and even tried it with the 'custom_functions.php' that accepts custom functions. Something's wrong. – TheBigK Oct 4 '12 at 13:35
I've updated my answer – Zlatev Oct 5 '12 at 5:30
Did this end up working for you with the update @TheBigK? – Tim Malone Jun 5 at 19:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.