WordPress How to Disable Comments Snippet

WordPress snippet – how to disable comments snippet. Need to disable ALL comments on your wordpress website? Place this snippet in you functions.php


* @snippet  WordPress - Disable Comments
* @code     https://techskilled.co.uk/snippets/wordpress-how-to-disable-comments-snippet
* @author   https://techskilled.co.uk
*/
function techskilled_disable_comments_post_types_support() {
	$post_types = get_post_types();
	foreach ($post_types as $post_type) {
		if(post_type_supports($post_type, 'comments')) {
			remove_post_type_support($post_type, 'comments');
			remove_post_type_support($post_type, 'trackbacks');
		}
	}
}
add_action('admin_init', 'techskilled_disable_comments_post_types_support');

We will now need to remove the comments form from the frontend of the website with the below snippet:


function df_disable_comments_status() {
	return false;
}
add_filter('comments_open', 'df_disable_comments_status', 20, 2);
add_filter('pings_open', 'df_disable_comments_status', 20, 2);

Thats it! Your website is now comments free!


NEED HELP?

If you are struggling to implement the SVG snippet then we can help from £9.99 – use our contact form below and we will get straight back to you!

HELP ME IMPLEMENT THIS SNIPPET

Leave a comment

Shares