Snippets: Add New Category “Block” to Blog Entries

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


add_filter( 'wpex_blog_entry_layout_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;
} );

Result:

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.