Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»CMS»WordPress»How to Disable Comments on Attachments in WordPress

    How to Disable Comments on Attachments in WordPress

    By RahulJanuary 11, 20191 Min Read

    Many of spammers target to media attachments on your WordPress website for comments. You can disable comments on your media attachments by using WordPress plugin or adding custom PHP code in your theme file. Below is the two methods described to disable comments on media attachments.

    Advertisement
    • Read: How to Disable Pingbacks and Trackbacks in WordPress

    Method 1 – Using Plugin

    Disable Comments WordPress plugin provides and option to disable comments globally on your WordPress website. This plugin allows you to disable all type of comments like post comments, pages comments, and media comments.

    Disable Comments on Attachments

    Method 2 – Using PHP Code

    If you don’t want to use any plugin, You can disable media comments by adding custom code in your WordPress theme. Edit functions.php in your WordPress theme file and append following code. This will disable comments on your media posts.

    1
    2
    3
    4
    5
    6
    7
    8
    function add_filter_media_comment ( $open, $post_id ) {
    $post = get_post( $post_id );
    if( $post->post_type == 'attachment' ) {
    return false;
    }
    return $open;
    }
    add_filter( 'comments_open', 'add_filter_media_comment', 10 , 2 );

    attachment spam comment spam comments WordPress
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    10 Simple Ways to Speed Up Your WordPress Website

    10 Simple Ways to Speed Up Your WordPress Website

    How to Add a Comments in Dockerfile

    How to Configure Nginx for WordPress Permalinks

    View 1 Comment

    1 Comment

    1. Thomas on January 11, 2019 1:42 am

      Thanks Rahul,

      Also remember to create and activate a child theme before doing this so any updates to the theme will not wipe out your hard work.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.