Javascript Redirect Traffic from Blogspot to WordPress Site

Ok. So you’ve had a blogspot blog for a little while and you’ve decided you want a WordPress site. How do you redirect traffic from the old site to the new site and lose as little traffic as possible in the process.

First. Use the import feature available in WordPress. From your Daskboard, look for Tools > Import

Second. Add some javascript code to your blogger template. Update the vars blogTitle and wordPressUrl to match your blogspot blog.

<script>
var blogTitle = 'Flexing My Kerkness';
var wordPressUrl = 'http://kerkness.ca';

if( document.title == blogTitle ){
window.location = wordPressUrl;
} else {
var newUrl = str_replace( document.title, blogTitle+’: ‘, ” );
window.location = wordPressUrl + ‘/?s=’ + newUrl;
}
function str_replace(haystack, needle, replacement) {
var temp = haystack.split(needle);
return temp.join(replacement);
}
</script>


Basically what this script does is redirects from your blogger site to your new domain while conducting a search based on the title of page being requested.

For example. If you had a post called “How to change outboard motor oil” on blogger. When you try and access the blogspot url for that post you will be directed to the new wordpress domain and you will search for posts matching “How to change outboard motor oil”. If that post was imported into word press and you haven’t changed the title. Users will be shown a link to the post on your new site. Also they may find any new or relevant content you’ve posted since making the change to WordPress.

0 comments: