WordPress Tweaks & Tuts?

Subscribe to TheCreatology via RSS | Email

Thesis Tutorial: Disable right click to Protect Content Copying on WordPress

by Aky Joe

Are you afraid of Content Thieves or your WordPress blog has a lot of copyrighted images and you don’t want just people to copy content. Believe me there is no full proof way to stop stealing stuff, however you can still lock the doors for people. Doesn’t Amaze you ? Here check out this tutorial to disable right click on website.

disable-right-click-on-wordpress

Disable Right Click on WordPress

You must have tried your luck with a lot JavaScript solutions and plugins, but they didn’t work with your WordPress Blog. Hmmm! Don’t worry, follow this 2-step thesis tutorial to disable right click on WP blog:

Step1: Update WordPress & Thesis Theme

Before we go ahead with the tutorial, its recommended to update latest version of WordPress and Thesis Theme. Don’t know how to do that ? Well, it is simple, refer to article Safely upgrade to latest version Thesis 1.8 ?

Already updated? Go to Step2.

Step2: JavaScript Code to Protect Content

Below is the working JS code to disable right click on WordPress blog. Add the code snippet in custom_functions.php in Thesis Theme.

NOTE: Make sure you take full backup of custom_functions.php file using FTP before modifying it or you can also refer to the article about how to safely edit custom_functions.php


/*
TheCreatology Tutorial - Disable Right Click
Author: Aky Joe
Email: [email protected]
*/
function joe_disable_right_click(){ ?>
<script language="Javascript">
/*<![CDATA[*/
document.oncontextmenu = function(){return false;};
/*]]>*/
</script>
<script type="text/javascript">
/*<![CDATA[*/
document.onselectstart=function(){
if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") {
return false;
}
else {
return true;
}
};
if (window.sidebar) {
document.onmousedown=function(e){
var obj=e.target;
if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") {
return true;
}
else {
return false;
}
};
}
/*]]>*/
</script>
<script type="text/javascript" language="JavaScript1.1">
/*<![CDATA[*/
if (parent.frames.length > 0) { top.location.replace(document.location); }
/*]]>*/
</script>
<script language="Javascript">
/*<![CDATA[*/
document.ondragstart = function(){return false;};
/*]]>*/
</script>
<?php
}
add_action( 'wp_head', 'joe_disable_right_click' );

Done adding above code? Save the custom_functions.php file and upload it to server using FTP. The above code will not only disable right click but will also disable highlight text on WordPress Blog.

Disable Right Click Demo

I hope you are not waiting for some fireworks, TRY TO RIGHT CLICK anywhere on your WordPress Page. 😉

Are we done ?

Yes, I hope the above demo made your mind.

One of my client’s requirement was to disable right click only on single posts. In such cases, you can use WordPress Conditional Tags with Code above in Step2.

With this we come to end of this article to disable right click to protect content copying on WordPress blog using Thesis Theme. If you have any query or further assistance is required, post feedback as comment below.

Similar Topics: ,

TheCreatology Support

Got a Query? We're ready, Just Say it!

If you have a doubt or a feedback, then get-in-touch with TheCreatology Support Team now.

Start a Hangout or Email Us

Are you looking for...

  • Logo Design
  • Web Development
  • Thesis Skin Design
  • Graphic Designing
  • Virtual Assistance
Hire Us!

7 Comments

{ read them below or add one }

Ammar February 4, 2012 at 12:51 pm

We can use CopyProtect WordPress plugin too. To disable right click on thesis and other WP themes

Reply

Aky February 4, 2012 at 7:02 pm

Yes we can, but for a small snippet code you wouldn’t want to depend on plugin. Whereas Plugin also increase number of php calls, hence its an unnecessary load on Server.

Reply

Cam January 26, 2013 at 10:32 pm

Hey Joe,

Awesome code man! Thank you very much for sharing your wonderful code with the community. What is your user name on DIY Forums please Joe so that I may send you a friend request?

My name on DIY is Campbell, I am sure that you have seen me on the forums in passing.

Once again, thanks for the code brother.

Cam

Reply

Cam January 26, 2013 at 10:37 pm

Joe,

Is there a way that you could modify the code so that logged in users for WP-ADMIN can right click? Or even better still, how about exempt user by IP Address only?

Cam

Reply

Aky Joe February 7, 2013 at 2:41 pm

Of course, where there is a way, there is a way. You can do so by wrapping the above code within:
if(!is_user_logged_in()) {
//Disable Right click code
}

I don’t log-in much into DIY forums, if I do, like Ghosts. You can reach me via contact form below, where it escapes you from a crocodile. 😀

Reply

Ghulam Mustafa February 16, 2014 at 8:43 pm

Amazing post. I like it.

Thanks for sharing

Reply

Lally Mahey January 15, 2016 at 9:35 pm

Thanks the give script of disable right click is fully working for me.

Before disable right-click you need to know its corn. It is used to navigate (go back/forward), reload and add to favorites. If you disable it, your visitors will suffer and likely avoid your blog.

instead of this, it is better to use disable selection of text or html :

Add the following html code to your BODY tag:
Here is how your BODY tag may look once implemented:

ondragstart=”return false” onselectstart=”return false”

Thanks

Reply

Leave a Comment

Previous post:

Next post:

Contact Aky




Yes, I agree that all information above is valid.

Simple question, what's...