Redirect traffic from blogspot to wordpress

How to Redirect Traffic From Blogspot Blog to WordPress Blog?

Redirect traffic from blogspot to wordpress

Most of the new bloggers start their blogging journey in blogspot platform. I also started my first blog in blogspot platform. Later I moved that in self-hosted WordPress platform.

If you are blogging for some time you’ve already realized that if you want to make money blogging then you should migrate from blogger to WordPress.

I wrote a tutorial a few days ago on how to migrate from blogger to WordPress.

After migrating from blogger to WordPress, there is a certain step you should take to redirect your blogspot traffic to WordPress.

If you don’t set this redirection properly, there is a vast possibility that if a visitor click on a link of your blog on Google search result they’ll see a broken link.

So, setting blogger to WordPress redirection is very important to guide your visitor to your newly setup self-hosted WordPress blog. It also tells search engines that your old blogspot blog is moved to a new location.

How this redirection works?

This redirection works in two steps.

In first step, it redirects visitors from your old blogspot blog to new WordPress blog.

In second step, once visitors land on your new WordPress blog, it will take them to the post they were trying to visit.

I know, at this point you are thinking that this is a complicated process. And your visitor won’t take that much effort to read a post.

But don’t worry. Your visitors won’t know about this. This will happen in back-end. They’ll visit your post as they normally do.

So, let’s redirect your blogspot blog traffic to your self-hosted WordPress blog.

Redirecting traffic from blogspot blog to WordPress blog

For successfully redirect traffic from blogspot blog to WordPress blog you’ll need to do two steps setup. One is in your old blogspot blog and another is in your new WordPress blog.

Setup redirection in blogspot blog

Open a new tab in your browser.

  • Login to your blogger account.
  • Go to blogspot dashboard > Theme.
  • On the template page, scroll down to the bottom of the page. Click on the link “Revert to classic template“. See the image below.

Blogspot to wordpress redirection

  • Once you clicked on the link you’ll be taken to the “Edit html” code area.
  • Once you are on “Edit html” code area, place the cursor in the code and type “ctrl+A” to select all the code.
  • Now copy the following code and paste into your blogger theme’s code. That means, you’ll need to replace everything in your blogger there’s code with the following code.
<html>

 <head>

  <title><$BlogPageTitle$></title>

   <script>

    <MainOrArchivePage>

    window.location.href="http://example.com/"

    </MainOrArchivePage>

    <Blogger>

     <ItemPage>

     window.location.href="http://example.com/?blogger=<$BlogItemPermalinkURL$>"

     </ItemPage>

    </Blogger>

   </script>

   <MainPage>

   <link rel="canonical" href="http://example.com/" />

   </MainPage>

   <Blogger>

    <ItemPage>

    <link rel="canonical" href="http://example.com/?blogger=<$BlogItemPermalinkURL$>" />

    </ItemPage>

   </Blogger>

 </head>

 <body>

  <MainOrArchivePage>

   <h1><a href="http://example.com/"><$BlogTitle$></a></h1>

  </MainOrArchivePage>

  <Blogger>

   <ItemPage>

    <h1><a href="http://example.com/?blogger=<$BlogItemPermalinkURL$>"><$BlogItemTitle$></a></h1>

    <$BlogItemBody$>

   </ItemPage>

  </Blogger>

 </body>

</html>
  • Replace “example.com” with your domain address.
  • Save your template.

You’ve successfully redirect your blogger blog to WordPress blog.

Setup redirection in your WordPress blog

At this point, your visitor will land your WordPress blog. But they will see broken link for the post they are trying to visit. To take them the the exact post, you have to put a code snippet in your WordPress theme’s function.php file.

Follow the steps below:

  • Copy the following code and paste it in your theme’s function.php file

function blogger_query_vars_filter( $vars ) {

  $vars[] = “blogger”;

  return $vars;

}

add_filter(‘query_vars’, ‘blogger_query_vars_filter’);

function blogger_template_redirect() {

  global $wp_query;

  $blogger = $wp_query->query_vars[‘blogger’];

  if ( isset ( $blogger ) ) {

    wp_redirect( get_wordpress_url ( $blogger ) , 301 );

    exit;

  }

}

add_action( ‘template_redirect’, ‘blogger_template_redirect’ );

  if ( preg_match(‘@^(?:https?://)?([^/]+)(.*)@i’, $blogger, $url_parts) ) {

    $query = new WP_Query (

      array ( “meta_key” => “blogger_permalink”, “meta_value” => $url_parts[2] ) );

    if ($query->have_posts()) {

      $query->the_post();

      $url = get_permalink();

    }

    wp_reset_postdata();

  }

  return $url ? $url : home_url();

}

You can edit your function.php file either from WordPress dashboard or from your hosting account.

Editing function.php from WordPress dashboard –

  • For editing the function.php file from your WordPress dashboard, go Appearance > Editor.

Blogger to WordPress redirection

  • Once you are on the editor page, click on the “Theme functions” that appears on the right side of the screen.

Blogger to WordPress redirection

  • Now paste the above code at the bottom of function code.

Alternatively, if you want to edit the function.php file from your hosting CPanel, follow the steps below:

  • Login to your hosting CPanel.
  • Then go to File Manager > WP Content.
  •  Click on function.php file.
  • Now paste the above code at the bottom of the function.php file.

You are all set. Your blogspot blog traffic now successfully redirected to your WordPress blog.

Caution: before editing your function.php file, always keep a backup copy of the file. So that, if anything goes wrong you can replace that later.

Say Something

If you are having trouble to implement blogger to WordPress redirection, please share in the comments below…

10 thoughts on “How to Redirect Traffic From Blogspot Blog to WordPress Blog?”

Leave a Comment

Your email address will not be published. Required fields are marked *