Skip to content

Instantly share code, notes, and snippets.

@elimn
Last active January 23, 2017 16:22
Show Gist options
  • Save elimn/9ce1c3e64d060b758e22627b815455ae to your computer and use it in GitHub Desktop.
Save elimn/9ce1c3e64d060b758e22627b815455ae to your computer and use it in GitHub Desktop.
MT | TEC | Remove JSON LD from loading on month view
<?php
/**
* Removes json LD from loading on month view
*/
function tribe_remove_json_ld_month() {
if ( tribe_is_month() ) {
tribe_remove_anonymous_hook( 'wp_head', 'Tribe__Events__Template__Month', 'json_ld_markup' );
}
}
add_action( 'template_redirect', 'tribe_remove_json_ld_month', 100 );
if ( ! function_exists( 'tribe_remove_anonymous_hook' ) ) {
/**
* Removes a filter or action added by anonymous objects
*
* Use this when you can not get the instance of a class attached to a hook.
* If the given method is attached multiple times to the hook, only one is removed.
*
* Example: tribe_remove_anonymous_hook( 'plugins_loaded', 'Tribe__Class', 'method_name' );
*
* @param string $tag Name of the filter or action.
* @param object|string $anonymous_class Object or classname that contains the method.
* @param string $method Method name.
* @param int $priority Priority the hook was attached to.
*/
function tribe_remove_anonymous_hook( $tag, $anonymous_class, $method, $priority = 10 ) {
global $wp_filter;
if ( ! isset( $wp_filter[ $tag ] ) ) {
return;
}
$wp_hook = $wp_filter[ $tag ];
// Ensure callbacks are attached to the priority
if ( ! isset( $wp_hook->callbacks[ $priority ] ) ) {
return;
}
foreach ( $wp_hook->callbacks[ $priority ] as $callback ) {
$function = $callback['function'];
// Skip callbacks that aren't methods
if ( ! is_array( $function ) ) {
continue;
}
// Check the class type and method name until we find a match.
if (
$function[0] instanceof $anonymous_class &&
$function[1] === $method
) {
remove_filter( $tag, $function, $priority );
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment