Sometime back we have published an article on how to completely disable Trackbacks and Pingbacks.
In this tutorial we will go over how to disable comments on Media and Attachments.
Let’s get started:
Step-1
Disable comments on Attachments or Media using WordPress hook.
- Open your theme’s functions.php file and add below code into it.
function crunchify_disable_comments_on_attchments( $open, $post_id ) { $crunchify_post = get_post( $post_id ); if( $crunchify_post->post_type == 'attachment' ) { return false; } return $open; } add_filter('comments_open', 'crunchify_disable_comments_on_attchments', 10 , 2 );
Here comments_open
determines whether the current post is open for comments.
This code works for all newly uploaded attachments.
Step-2
For Existing attachments, you need to manually disable comments using Query.
- Open phpMyAdmin
- Execute below two queries
UPDATE wp_posts SET ping_status='closed' WHERE post_type = 'attachment'; UPDATE wp_posts SET comment_status='closed' WHERE post_type = 'attachment';
Step-3
Next you need to delete existing attachment comments.
- Open phpMyAdmin
- Execute below query
DELETE FROM `wp_comments` WHERE `comment_type` = 'trackback';
And you are all set.
Now, you have disabled and deleted all comments on Attachments and Media files.
Let me know if you face any issue running above queries or function.
Thank you and Happy blogging.
The post In WordPress How to Disable comments on Media, Attachments appeared first on Crunchify.
0 Commentaires