Skip to main content

Show a teaser card for locked episodes

Free Intermediate Since v1.0.0

Where the hide-locked recipe removes locked items entirely, this recipe replaces them with a teaser card that shows the episode title, the first 40 words of the episode description, and a subscribe call-to-action link. Locked-out visitors see what the episode is about without hearing it — keeping the episode discoverable and giving them a clear next step.

One callback covers all three episode-listing shortcodes ([benecaster_episodes], [benecaster_latest_episode], [benecaster_related_episodes]). Accessible episodes pass through unchanged.

Description source. The recipe reads _benecaster_episode_description_rss, the shortest of the four episode-description fields. Swap the meta key for _benecaster_episode_description_short or _benecaster_episode_content_full if your team uses those for editorial summaries (see the Data Model reference for the full list).

Word count. 40 words is a reasonable default — enough context to convey what the episode covers, short enough to leave curiosity. Adjust the wp_trim_words() count to your show’s copy style.

Compose with show_locked="false" for a mixed strategy. Set show_locked="false" on shortcode instances where you want locked items hidden; leave show_locked="true" (the default) on instances where you want teasers. The attribute’s fast-path skip runs before this filter — hidden instances bypass the callback, teaser instances invoke it.

Code

<?php
// Replace locked-episode markup with a "first 40 words + subscribe CTA" teaser card.
//
// Fires from all three episode-listing shortcodes — one callback covers
// every surface. Includes the show ID so the CTA link can point at the
// right per-show subscribe page.
add_filter( 'benecaster_episode_item_output', function ( string $html, int $episode_id, int $show_id, string $user_tier, bool $is_locked ): string {
    if ( ! $is_locked ) {
        return $html;
    }

    $title       = get_the_title( $episode_id );
    $permalink   = get_permalink( $episode_id );
    $description = get_post_meta( $episode_id, '_benecaster_episode_description_rss', true );
    $teaser      = wp_trim_words( wp_strip_all_tags( (string) $description ), 40, '…' );

    // Point the CTA at the show's Subscribe shortcode landing page.
    // Adjust the URL to whatever your site uses for subscription checkout.
    $subscribe_url = home_url( '/subscribe/?show=' . $show_id );

    ob_start();
    ?>
    <div class="my-episode-teaser">
        <h3 class="my-episode-teaser__title"><?php echo esc_html( $title ); ?></h3>
        <p class="my-episode-teaser__description"><?php echo esc_html( $teaser ); ?></p>
        <p class="my-episode-teaser__cta">
            <a href="<?php echo esc_url( $subscribe_url ); ?>">
                Subscribe to hear this episode
            </a>
             · 
            <a href="<?php echo esc_url( $permalink ); ?>">Episode page</a>
        </p>
    </div>
    <?php
    return (string) ob_get_clean();
}, 10, 5 );

View on GitHub →

Hooks Used

  • benecaster-episode-item-output