So Tumblr is showing many 404 pages, which I want to redirect to the homepage. Unfortunately, due to my mad coding skills (read: no coding skills), I am still unable to make this code work.
Here it is:
`<script type="text/javascript"
src="http://static.tumblr.com/5huhcpw/k3elvd7u3/jquery.min.js"></script>
<script type="text/javascript"> $( init );
function init() {
var pageTitle = $('h2').text();
if (pageTitle == "Not Found”):
redirect( 'http://example.com/', 301 );
exit;
endif;
}
</script>`
Every Tumblr 404 page has a "Not Found" title. Now, if we see this text it should 301 to the homepage. Is this possible? Appreciate your help. :-)
It looks like you have php and javascript/jquery mixed up possibly.
I managed to get the following code to work:
var pageTitle = $('h2').text();
if (pageTitle == "Not Found") {
window.location.replace('http://example.com/');
}
Here is a jsfiddle: http://jsfiddle.net/YQsDv/