Support » Developing with WordPress » Remove Comments for Specific Post Categories

  • Resolved webcitymedia

    (@webcitymedia)


    There are some outdated plugins but looking for a current function.php entry to remove comment functionality except for a specific post category.

    Found some old code which does not work but in the neighborhood.

    add_action( 'wp_enqueue_scripts', 'remove_comments_specific_categories' );
    
    function remove_comments_specific_categories() {
    	if ( !in_category( '17' ) ) {
    		remove_post_type_support($post_type, 'comments');
    	}
    }

    Any suggestions would be helpful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I would alter the theme template which displays comments and the comment form, or modify the call that loads this template. The template is usually comments.php. Get the post’s categories, and if any of them are the comment suppression category, suppress any comment related output by not making the load template call or by calling return; from the actual template.

    Because several templates may load the one comments template, it’s probably easier to alter that one template. YMMV, depending on how your theme manages comments.

    Thread Starter webcitymedia

    (@webcitymedia)

    Thanks Bcworkz!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove Comments for Specific Post Categories’ is closed to new replies.