Skip to content

Instantly share code, notes, and snippets.

@mrwweb
Created October 28, 2019 20:51
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mrwweb/519725f8dbb2893995c0e22abd5afe8e to your computer and use it in GitHub Desktop.
Show Event Website block in Event List for The Events Calendar
<?php
/**
* Find, parse, and return the Website Button for Tribe's The Events Calendar events
*/
function mrw_get_tribe_website_button( $post_id = false ) {
if( ! $post_id ) {
$post_id = get_the_ID();
}
$post_content = get_post_field( 'post_content', $post_id );
$blocks = parse_blocks( $post_content );
$website_block = '';
foreach ( $blocks as $block ) {
if( 'tribe/event-website' === $block['blockName'] ) {
$website_block = render_block( $block );
break;
}
}
return $website_block;
}
// You may want to use a different action depending on where you want to place the button
add_action( 'tribe_events_inside_cost', 'mrw_add_website_link' );
function mrw_add_website_link() {
if( tribe_is_list_view() ) {
echo mrw_get_tribe_website_button();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment