Snippets: Custom Blog Entry Blocks/Sections & Ouput

This is very similar to the snippet example here here but it allows you to have a custom output function rather then creating a template part. It also allows you to override any of the default "blocks" with your custom output!

// This example adds a custom block/section to the blog entries front-end display
// If you wish to add the block to the Customizer layout settings use the "wpex_blog_entry_blocks" filter to do so
// IMPORTANT: Version 4.0+ required
add_filter( 'wpex_blog_entry_layout_blocks', function( $blocks ) {

	// Example 1: Add new block with an anonymous function for the output
	$blocks['my_custom_block_1'] = function() {

		echo 'test';


	// Example 2: Add new block with a custom function as the output
	$blocks['my_custom_block_2'] = my_function_name();

	// Example 3: Add new block with an anonymous function that returns a template part
	$blocks['my_custom_block_3'] = function() {

		get_template_part( 'your-template-part' );


	// Example 4: Override the default featured_media block
	$blocks['featured_media'] = function() {

		echo 'My custom featured media';


	// Return blocks
	return $blocks;

} );

Snippet Type: PHP

Posted Under: Blog

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