0

The Problem

I am trying to remove an JSON+LD block being added by a WordPress plugin called The Events Calendar.

I believe it is being added by the function called: Tribe__Events__Template__Single_Event within which the function named google_data_markup is responsible for the actual markup which I am trying to stop/prevent from being added to the HTML.

The Code

From my limited understanding of this, I need to remove this action:

add_action( 'wp_head', array( $this, 'google_data_markup' ) );.

I believe it is being called here, in Single_Event.php:

if ( ! class_exists( 'Tribe__Events__Template__Single_Event' ) ) {
    /**
     * Single event template class
     */
    class Tribe__Events__Template__Single_Event extends Tribe__Events__Template_Factory {

        protected $body_class = 'events-single';

        public function hooks() {
            parent::hooks();

            // google data markup
            add_action( 'wp_head', array( $this, 'google_data_markup' ) );

        }

        public function google_data_markup() {
            $event_markup = new Tribe__Events__Google_Data_Markup__Event();
            $html = apply_filters( 'tribe_google_data_markup_json', $event_markup->script_block() );
            echo $html;
        }

        /**
        ...

What I've tried

Initial Attempts

After finding this on StackOverflow, and this on WordPress Dev Exchange, I tried:

remove_action( 'wp_head', array( 'Tribe__Events__Template__Single_Event', 'google_data_markup' ) );

and

global $Tribe__Events__Template__Single_Event;
remove_action( 'wp_head', array( $Tribe__Events__Template__Single_Event, 'google_data_markup' ) );

But it did not work.

Subsequent Attempts

After getting even more desperate and seeing this slim thread (the example in that thread seems very similar to mine but no answer provided that I understand), and this, I've also tried this, with the & before the variable name (why?):

remove_action( 'wp_head', array( &$Tribe__Events__Template__Single_Event, 'google_data_markup' ) );

I've also tried this:

function remove_the_events_calendar_jsonld() {
    remove_action( 'wp_head', array( $Tribe__Events__Template__Single_Event, 'google_data_markup' ) );
}
add_action( 'plugins_loaded', 'remove_the_events_calendar_jsonld', 1 );

as well as:

remove_action( 'Tribe__Events__Template__Single_Event', 'google_data_markup' );

Please help. At this point I have no idea if I am making a simple syntax or logic error of sorts, or if I am completely confused and oblivious to how functions, classes and actions work.

1

Figured it out with help from an SO user!

This will remove the ld+json block added by The Events Calendar:

add_filter( 'tribe_google_data_markup_json', '__return_empty_string', 20 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.