Snippets: Add New “Blocks” To The Portfolio Post Layout

The following snippet will show you how to add a custom block to your portfolio layout which you can enable in the Customizer and then control the output via a callback or anonymous function, however, did you know you can build custom templates via the WordPress admin?

// Add new option to select from in the Customizer.
add_filter( 'wpex_portfolio_single_blocks_choices', function( $blocks ) {
    $blocks['tags'] = __( 'Tags', 'wpex' );
    return $blocks;
}, 10, 2 );

// Render the new custom block.
// Note you can create either add code like this or you can make a new file in your child theme at partials/portfolio/portfolio-single-tags.php
// to render the output instead.
add_filter( 'wpex_portfolio_single_blocks', function( $blocks ) {

    if ( isset( $blocks['tags'] ) ) {

        $blocks['tags'] = function() {

            // Get tags
            $taxonomy   = 'portfolio_tag';
            $show_links = true;
            $echo       = false;
            $tags       = wpex_list_post_terms( $taxonomy, $show_links, $echo );

            // Output tags
            if ( $tags ) {
                echo '<div class="my-portfolio-tags clr">' . $tags . '</div>';
            }
        };

    }

    return $blocks;
} );
All PHP snippets should be added via a child theme's functions.php file or via the Code Snippets Plugin (or alternative plugin)