Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active February 20, 2020 18:05
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 bordoni/1a81670f0cdd66bb1ed437c05a0337a3 to your computer and use it in GitHub Desktop.
Save bordoni/1a81670f0cdd66bb1ed437c05a0337a3 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: The Events Calendar Extension: Missing Events Single JSON-LD
* Plugin URI: https://theeventscalendar.com/extensions/---the-extension-article-url---/
* GitHub Plugin URI: https://github.com/mt-support/tribe-ext-extension-template
* Description: Makes sure JSON-LD is present on Single Event for V2.
* Version: 1.0.0
* Author: Modern Tribe, Inc.
* Author URI: http://m.tri.be/1971
* License: GPL version 3 or any later version
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: tribe-ext-v2-single-event-json-ld
*
* This plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
add_action( 'wp', function() {
if ( ! class_exists( 'Tribe__Events__JSON_LD__Event' ) ) {
return;
}
if ( ! class_exists( 'Tribe__Events__Main' ) ) {
return;
}
// Check if we are in a single page.
if ( ! is_singular( Tribe__Events__Main::POSTTYPE ) ) {
return;
}
$context = tribe_context();
// One more check for our Post Type.
if ( ! $context->is( 'tec_post_type' ) ) {
return;
}
// Bail when that action already exists.
if ( has_action( 'wp_head', [ Tribe__Events__JSON_LD__Event::instance(), 'markup' ] ) ) {
return;
}
// Print JSON-LD markup on the`wp_head`
add_action( 'wp_head', [ Tribe__Events__JSON_LD__Event::instance(), 'markup' ] );
} );
@bordoni
Copy link
Author

bordoni commented Feb 20, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment