cliff
3/1/2018 - 9:25 PM

The Events Calendar: Add Open Graph to <head> of Events Archive views.

The Events Calendar: Add Open Graph to of Events Archive views.

<?php

/**
 * The Events Calendar: Add Open Graph to <head> of Events Archive views.
 *
 * @link https://gist.github.com/cliffordp/5ed25b8bfb024efe73d1ce6c42d960aa
 * @link http://ogp.me/
 */
/**
 * The Events Calendar: Add Open Graph to <head> of Events Archive views.
 *
 * @link https://gist.github.com/cliffordp/5ed25b8bfb024efe73d1ce6c42d960aa
 * @link http://ogp.me/
 */
function cliff_add_open_graph_tec_archive_views() {
	// !!! CHANGE THIS URL !!!
	$tec_archive_view_og_image_url = 'https://theeventscalendar.com/content/uploads/2013/07/screenshots4-2_single-event.png';

	if ( ! class_exists( 'Tribe__Events__Main' ) ) {
		return false;
	}

	$tecmain = Tribe__Events__Main::instance();

	if (
		is_main_query()
		&& is_post_type_archive( $tecmain::POSTTYPE )
	) {
		printf( '<meta property="og:image" content="%s" />%s', $tec_archive_view_og_image_url, PHP_EOL );
	}
}

add_action( 'wp_head', 'cliff_add_open_graph_tec_archive_views' );