Skip to main content

Add a Custom Section to the Show Page

Free Beginner Since v1.0.0

Use benecaster_after_show_episode_list to inject HTML below the episode listing without overriding a template file. Each show page action hook fires with $show_id as its only argument. Swap to benecaster_after_show_header, benecaster_after_show_subscribe_links, benecaster_after_show_tiers, or benecaster_after_show_stats to inject at a different position.

Code

<?php
add_action(
    'benecaster_after_show_episode_list',
    function ( int $show_id ): void {
        $newsletter_url = get_post_meta( $show_id, '_my_newsletter_url', true );
        if ( ! $newsletter_url ) {
            return;
        }
        printf(
            '<div class="my-show-newsletter"><h3>%s</h3><a href="%s" class="benecaster-btn">%s</a></div>',
            esc_html__( 'Stay in the loop', 'my-plugin' ),
            esc_url( $newsletter_url ),
            esc_html__( 'Subscribe to the newsletter', 'my-plugin' )
        );
    },
    10,
    1
);

View on GitHub →

Hooks Used