Skip to content

Snippet: Conditionally Enable or Disable Single Blog “Sections/Blocks”

Rather then using custom code you can always create Dynamic Templates with different designs for different parts of your site. And you can use our free plugin to assign them to different taxonomy terms.
/**
 * Using the filter "totaltheme/blog/single_blocks" you can enable/disable blocks from the front-end
 * on single blog posts
 *
 * Default block ID's: featured_media, title, meta, post_series, the_content, post_tags, social_share, author_bio, related_posts_comments
 *
 * @link http://total.wpexplorer.com/docs/blog-single-post-builder/
 */
add_filter( 'totaltheme/blog/single_blocks', function( $blocks ) {

    // Remove related items for all items except those in category "news"
    if ( ! in_category( 'news' ) ) {
        unset( $blocks['related'] );
    }

    // 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