I’ve read a lot of topics about redirecting Tumblr to WordPress, but I still canât find a suitable solution.
Here is the problem: I want to redirect jeby.tumblr.com, a Tumblr blog, to the new jeby.it, a WordPress (WIP) blog with a custom domain and web space etc. Iâve already imported all contents, now all I want is to âautomagicallyâ redirect every single post from
jeby.tumblr.com/post/[POST ID]/some-slug
to
jeby.it/2012/05/some-slug
I know that the post year and month are available in the Tumblr HTML code, as they are used to compose the permalink. I canât use .htaccess
redirects because the Tumblr blog is hosted by Tumblr.
Iâve done the same thing with Blogspot, where I found a plugin that created the right JavaScript code to paste into the Blogspot model and get automatic redirection.
As you have realized already, you will need to do the redirection client side. How to achieve that is a matter of Tumblrâs theme templating systemâs possibilities and limitations.
{Year}
and{MonthNumberWithZero}
tokens respectively; that gets you2012
and05
.{Permalink}
token.{block:Posts}
block and Tumblr does the figuring out how many posts to display inside that. That means thatmeta http-equiv="Refresh"
tags are out of the question, as they would also be included in all non-single-posts pages.Luckily, Tumblr does let you include arbitrary JavaScript in your template, and that is the way to go:
add the following line inside the
{block:Posts}
block:Style your
redirdata
spans withdisplay:none
in your CSS to hide them (or style them inline â considering their intended use, there is little point in being dogmatic).now add a script to your
<head>
to parse these and redirect to the WordPress URL. As you want to do this for every possible visitor, i.e. as cross-browser compatibly as possible, I recommend using jQuery. Include it with:or any other hosted source (see the jQuery docs for CDN URLs). Then add the following script:
and your single-post page should automatically redirect all visitors to the WordPress post page (if they have JavaScript enabled, of course). I am sure you will figure out to adapt this to tag archives, searches and such, if need be.
Caveat Empteor: this will only work if the slugs of your WP posts match the slugs of your Tumblr posts â crucially also in the case of Tumblr posts with no textual slug (meaning you WP slug needs to match the numeric Tumblr post ID in that case).