[Resolved] How to disable right click in wordpress without any plugin

Home Forums Support [Resolved] How to disable right click in wordpress without any plugin

Home Forums Support How to disable right click in wordpress without any plugin

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1326149
    Carlos

    Hello there,

    I need to add code for to disable right click on WordPress without any plugin, add any codes but not working and broken the site.

    I don’t want other plugin, have 21 plugins and I’m wish delete plugins 1 to 1 but need options.

    Thank you very much!

    #1326517
    David
    Staff
    Customer Support

    Hi there,

    this article provides the one line of JS you require and some very good reasons why you shouldn’t:

    https://stackoverflow.com/a/737043

    #1332087
    Carlos

    Hello David,

    where I should add this code?

    document.addEventListener('contextmenu', event => event.preventDefault());

    In my functions? I’m using the child theme.

    Thank you very much

    #1332294
    David
    Staff
    Customer Support

    Simplest way.
    Create a new Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    Add the script like so:

    <script>
    // Code goes here
    </script>

    Select the WP_Footer hook.
    And set the Display Rules to Entire Site.

    #1343121
    Carlos

    Hello David,

    the code is not working. Your code only disable the right click but not the copy and paste.

    Please I need your help.

    Thank you very much!

    #1343132
    Carlos

    Hello there!

    This code here working like charm !

    <body oncontextmenu="return false" onselectstart="return false"
    			onkeydown="if ((arguments[0] || window.event).ctrlKey) return false"></body>

    Thank you very much!

    #1343334
    David
    Staff
    Customer Support

    Glad to hear that

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.