Skip to content

Snippet: Alter Single Post “Blocks” for Posts in Specific Category

Rather then using custom code you can instead create a Dynamic Template with a custom design for your category then use our free plugin to assign it.

add_filter( 'totaltheme/blog/single_blocks', function( $blocks ) {

	// Alter blocks for specific category
	if ( ! is_admin() && in_category( 'parent' ) ) {

		/**** Available block names:

			featured_media
			title
			meta
			post_series
			the_content
			post_tags
			social_share
			author_bio
			related_posts
			comments

		****/

		// Remove meta
		unset( $blocks['meta'] );

		// Remove author box
		unset( $blocks['author_bio'] );

	}

	// Return blocks
	return $blocks;

} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top