The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Disable Image Dragging

Shared by Amit Dholiya · July 4, 2026

34 views
1 upvote
Back to Snippets

Helpful for portfolio, photography, and artwork websites.

Steps

  1. Open functions.php.
  2. Add the code below.
  3. Save the file.

Done — images cannot be dragged by visitors.

function disable_image_dragging() {
    ?>
    <script>
    document.addEventListener('dragstart', function(e) {
        if (e.target.tagName === 'IMG') {
            e.preventDefault();
        }
    });
    </script>
    <?php
}
add_action('wp_footer', 'disable_image_dragging');
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by