Right click and Selection disabled Snippet

Category: | Tag:
add_action('wp_footer', function () {
    ?>
    <style>
        body {
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        input, textarea, [contenteditable="true"] {
            -webkit-user-select: text;
            -moz-user-select: text;
            -ms-user-select: text;
            user-select: text;
        }
    </style>

    <script>
        document.addEventListener('contextmenu', function(e) {
            if (!e.target.closest('input, textarea, [contenteditable="true"]')) {
                e.preventDefault();
            }
        });
    </script>
    <?php
});
Copyright © 2026 Siam Naulak.
magnifiercrossmenu