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.
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: help@thecreatology.com */ 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.
We can use CopyProtect WordPress plugin too. To disable right click on thesis and other WP themes
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.
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
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
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. 😀
Amazing post. I like it.
Thanks for sharing
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