WordPress Spam on Attachment Pages

The other day I recognized in the dashboard of one of my pages, that I had 1600 something unanswered comments. ALTHOUGH I completely disabled comments on my page. I used a fancy theme together with a bunch of plugins to enable a Flickr’ish kind of gallery display with a lightbox. It turns out that wordpress has something like attachment pages and that you can still post comments there. I disabled them with a filter in functions.php:

function filter_media_comment_status( $open, $post_id ) {
    $post = get_post( $post_id );
    if( $post->post_type == 'attachment' ) {
        return false;
    }
    return $open;
}
add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 );

Another way would be to edit the associated template attachment-* within the template hierarchy and remove all the form-related stuff from there.


Posted

in

by

Tags: