Skip to main content

benecaster_episode_page_blocks

Filter Free Since v1.0.0

Filters the ordered block list for a specific episode page before rendering. The list is resolved from the show’s `_benecaster_episode_page_blocks` meta setting. Each item is an associative array with `slug` (string), `enabled` (bool), and `config` (array) keys.

Removing an item from the array suppresses that block without touching show settings — this is the cleanest way to conditionally hide a block for specific content or shows without a global toggle. You can also reorder items to change the injection sequence, or programmatically enable or disable blocks by modifying the `enabled` key. This filter fires before any block renderers run, so it is more efficient than returning an empty string from a [benecaster_episode_page_block_{slug}](/hooks/benecaster_episode_page_block_{slug}/) filter when you want to skip rendering entirely.

Parameters

Name Type Default Description
$blocks array Ordered array of {slug, enabled, config} block objects
$episode_id int ID of the episode being rendered
$show_id int ID of the show

Returns: array

Examples

Hide subscribe CTA for free previews

add_filter( 'benecaster_episode_page_blocks', function( $blocks, $episode_id, $show_id ) {
    // Disable the subscribe_cta block for episodes tagged as free previews.
    $is_free_preview = get_post_meta( $episode_id, '_episode_free_preview', true );
    if ( $is_free_preview ) {
        $blocks = array_filter( $blocks, fn( $b ) => 'subscribe_cta' !== $b['slug'] );
    }
    return array_values( $blocks );
}, 10, 3 );

Suppress block for specific show

add_filter( 'benecaster_episode_page_blocks', function( array $blocks, int $episode_id, int $show_id ): array {
    if ( $show_id === 42 ) {
        return array_filter( $blocks, fn( $b ) => $b['slug'] !== 'related_episodes' );
    }
    return $blocks;
}, 10, 3 );

Reorder blocks by priority

add_filter( 'benecaster_episode_page_blocks', function( array $blocks, int $episode_id, int $show_id ): array {
    usort( $blocks, function( $a, $b ) {
        $order = [ 'social_links' => 0, 'episode_nav' => 1 ];
        return ( $order[ $a['slug'] ] ?? 99 ) <=> ( $order[ $b['slug'] ] ?? 99 );
    } );
    return $blocks;
}, 10, 3 );

Notes

Removing an item from the $blocks array suppresses the block without modifying show settings — this is more efficient than returning an empty string from benecaster_episode_page_block_{slug} because the block renderer never runs. Always call array_values() after array_filter() to re-index the array.

Affects

  • EpisodePageRenderer injection