Skip to content

Instantly share code, notes, and snippets.

@codename065
Created February 4, 2021 08:10
Show Gist options
  • Save codename065/0043470a64e5b58a931e329fc268356d to your computer and use it in GitHub Desktop.
Save codename065/0043470a64e5b58a931e329fc268356d to your computer and use it in GitHub Desktop.
How to Disable Text Selection, Copy/Paste and Context Menu on right mouse button click in WordPress
<?php
function your_function() {
?>
<script>
jQuery(document).ready(function(){
function disableselect(e) {
return false;
};
function reEnable() {
return true;
};
document.onselectstart = new Function ("return false")
if (window.sidebar) {
document.onmousedown = disableselect
document.onclick = reEnable
};
jQuery(document).bind("contextmenu",function(e){
return false;
});
jQuery(document).bind("copy",function(e){
return false;
});
jQuery(document).bind("paste",function(e){
return false;
});
jQuery(document).bind("select",function(e){
return false;
});
});
</script>
<?php
}
add_action('wp_footer', 'your_function');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment