Lock down Tumblr and still use the API

Written by Ben on January 13, 2015

If you’re trying to use the Tumblr API, develop the website and also hide it from the general public… you will probably be having a few problems… just like we were!

If you are having issues, below are a few handy steps to help solve the problem:

  • Delete all robots.txt files that may be in your theme – if you can’t find any, no worries! Just move onto the next step…
  • Turn off Index in search engines – click to right on the icon of a person, settings and then scroll to the bottom and turn off – ‘Allow this blog to appear in search results
  • Use the below code for your password script – feel free to edit how you feel fit

 

First, create a div that will block any user from seeing the content on your site. I’ve added the script in-line to make sure there are no issues with loading external stylesheets – remember to change the background image!

 

<div style="background: url(image) no-repeat center center white; position: fixed; z-index: 1000; top: 0; left: 0; right: 0; bottom: 0;"></div>

 

Next you’ll need a little script to remove the div if it’s a correct password. If they enter a wrong password, we’ve got it set up to empty all of the contents of the site and redirect them – this makes sure they wouldn’t be able to see anything on your site!

 

var msg = window.prompt("Enter Your Password", "Password");

jQuery( document ).ready(function() {

	if(msg != "password"){
		jQuery("body").remove();
		window.location.replace("https://www.bigeyedeers.co.uk/");
	}else{
		jQuery(".pswdtest").remove();
	}

});

 

Change “password” to whatever you would like the password to be and also replace the website to whatever you’d like!

Finally, upload this script to Tumblr and hook it up to your theme. You’ll now be able to use your website to generate an API key to use more features of Tumblr whilst still having a locked website!

 

If you do have any questions for us about your current site or an upcoming project, feel free to get in touch and we would be more than happy to help out! Head to our contact page for the details to get in touch with the team in either our Cardiff or Cornwall offices!