Prevent users from right-clicking on your website. Text & Image

How to disable right-click images on a website

Plugin:

WP Copy Pro  Protection

Using Javascript

Past this in the footer.php of your theme, right above the body closing tag </body>

<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Geek Site.in


var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// --> 
</script>
Using code

Head over to your body tag. Your body tag will reside inside the header.php of a WordPress website and in most other websites.

Paste “oncontextmenu=”return false” in the body tag. See examples below:

<body oncontextmenu="return false">
 text
</body>


body <?php body_class(); ?> oncontextmenu="return false;" style=" -moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer */
-khtml-user-select: none; /* KHTML browsers (e.g. Konqueror) */
-webkit-user-select: none; /* Chrome, Safari, and Opera */
-webkit-touch-callout: none; /* Disable Android and iOS callouts*/">
<?php
$class = array();
if( false !== strpos( $template, 'dt-slideshow-' ) ) {
$slider_options = get_post_meta( $post->ID, '_dt_slider_layout_options', true );
if( $slider_options && isset($slider_options['slider']) ) {
switch( $slider_options['slider'] ) {
case 'carousel': $class[] = 'carous'; break;
case 'photo_stack': $class[] = 'vert';
}
}
}

How to disable right-click on text or select text on a website

With ccs

Go to your style.css for WordPress. This will be located in your theme folder. Create a class. I called mine “.disable-selection”. You can paste the following code into your style.css.

 

.disable-selection {
     -moz-user-select: none; /* Firefox */
      -ms-user-select: none; /* Internet Explorer */
   -khtml-user-select: none; /* KHTML browsers (e.g. Konqueror) */
  -webkit-user-select: none; /* Chrome, Safari, and Opera */
  -webkit-touch-callout: none; /* Disable Android and iOS callouts*/

 

Call this class in your body tag. You can find the body tag in the header.php file of your theme.
Example:

<body <?php body_class(); ?>