Skip to content

Snippet: Add New Category “Block” to Blog Entries

// Add a new custom block option to the entry blocks in the Customizer
add_filter( 'totaltheme/blog/entry_blocks/choices', function( $blocks ) {
    $blocks['custom-category'] = __( 'Category', 'wpex' );
    return $blocks;
} );


add_filter( 'totaltheme/blog/entry_blocks', function( $blocks ) {
	if ( isset( $blocks['custom-category'] ) && function_exists( 'wpex_get_first_term_link' ) ) {
		$blocks['custom-category'] = function() {
			echo '<div class="custom-entry-category-tag">' . wpex_get_first_term_link( get_the_ID(), 'category' )  . '</div>';
		};
	}
	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