Last active
August 23, 2018 05:19
-
-
Save cliffordp/af0b1645ff0e5e25edc10ffcccf2df29 to your computer and use it in GitHub Desktop.
MT - TEC - Support Accelerated Mobile Pages (AMP) for The Events Calendar's Events, Organizers, and Venues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* MT - TEC - Support Accelerated Mobile Pages (AMP) for The Events Calendar's Events, Organizers, and Venues | |
* | |
* See the comments in tribe_single_event_amp_template()!!! | |
* GIF of using AMP plugin's default template: https://cl.ly/382y0d221n38 | |
* | |
* from https://gist.github.com/cliffordp/af0b1645ff0e5e25edc10ffcccf2df29 | |
* | |
* @see tribe_single_event_amp_template | |
* | |
* @link https://wordpress.org/plugins/amp/ | |
* @link https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-post-type-support | |
*/ | |
// Register the Custom Post Types with AMP | |
add_action( 'amp_init', 'tribe_events_orgs_venues_support_amp' ); | |
function tribe_events_orgs_venues_support_amp() { | |
if ( | |
! class_exists( 'Tribe__Events__Main' ) | |
|| ! defined( 'AMP_QUERY_VAR' ) | |
) { | |
return false; | |
} | |
// Register Events | |
add_post_type_support( Tribe__Events__Main::POSTTYPE, AMP_QUERY_VAR ); | |
// Override AMP's templating with Event Single template | |
if ( class_exists( 'Tribe__Events__Templates' ) ) { | |
add_filter( 'amp_post_template_file', 'tribe_single_event_amp_template', 10, 3 ); | |
} | |
// Organizers and Venues require Events Calendar PRO to be activated | |
if ( class_exists( 'Tribe__Events__Pro__Main' ) ) { | |
// Register Organizers | |
add_post_type_support( Tribe__Events__Main::ORGANIZER_POST_TYPE, AMP_QUERY_VAR ); | |
// Register Venues | |
add_post_type_support( Tribe__Events__Main::VENUE_POST_TYPE, AMP_QUERY_VAR ); | |
} | |
} | |
/** | |
* Override the default template for Accelerated Mobile Pages (AMP) for The Events Calendar's Events | |
* | |
* Requires creating your own file at [your-child-theme]/tribe-events/single-event-amp.php | |
* based on single-event.php and removing the items you do not want (including removing | |
* do_action() where you see appropriate). | |
* You could also just change 'single-event-amp' to 'single-event' and then the pre-existing | |
* single-event.php template will load but its CSS and JS will not... so what's the point... | |
* | |
* @param string $file | |
* @param string $type | |
* @param WP_Post $post | |
* | |
* @return string | |
*/ | |
function tribe_single_event_amp_template( $file, $type, $post ) { | |
if ( 'single' === $type && Tribe__Events__Main::POSTTYPE === $post->post_type ) { | |
// $file = Tribe__Events__Templates::getTemplateHierarchy( 'single-event-amp' ); | |
} | |
return $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment