Skip to content

Instantly share code, notes, and snippets.

@jeherve
Last active July 10, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeherve/ec1293761c71f56d4362e2260fbe810f to your computer and use it in GitHub Desktop.
Save jeherve/ec1293761c71f56d4362e2260fbe810f to your computer and use it in GitHub Desktop.
[Jetpack] Display a Podcast player anywhere. See https://wordpress.org/support/topic/embedding-the-podcast-player-with-code/
<?php
/**
* Display a Podcast player anywhere.
* Pulled from extensions/blocks/podcast-player/podcast-player.php
* @see https://github.com/Automattic/jetpack/blob/b88b1edbdce4d8576ce9be02a9093702ae112fed/extensions/blocks/podcast-player/podcast-player.php
* @see https://wordpress.org/support/topic/embedding-the-podcast-player-with-code/
*/
function jeherve_display_podcast() {
// bail early if Jetpack isn't installed.
if ( ! class_exists( 'Jetpack' ) ) {
return;
}
// Load the necessary libs.
if ( ! class_exists( 'Jetpack_Podcast_Helper' ) ) {
jetpack_require_lib( 'class-jetpack-podcast-helper' );
}
$attributes = array(
'url' => 'https://distributed.blog/category/podcast/feed/',
'itemsToShow' => 2,
'primaryColor' => 'accent',
'hexPrimaryColor' => '#e22658',
'secondaryColor' => 'primary',
'hexSecondaryColor' => '#000000',
'backgroundColor' => 'subtle-background',
'hexBackgroundColor' => '#dbdbdb',
'showCoverArt' => true,
'showEpisodeDescription' => true,
);
$player_data = Jetpack_Podcast_Helper::get_player_data( $attributes['url'] );
// No info from that feed. Bail.
if ( is_wp_error( $player_data ) ) {
return;
}
echo \Automattic\Jetpack\Extensions\Podcast_Player\render_player( $player_data, $attributes );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment