Support » Plugin: The Events Calendar » Add meta description to main events page when using WP SEO by Yoast

  • Resolved mredinius

    (@mredinius)


    Struggled with this for a bit, but the following code will add seo meta descriptions to the events pages when using WP SEO by Yoast.

    Put this in your theme’s functions.php

    add_filter('wpseo_metadesc','my_custom_description');
    function my_custom_description($description) {
    	if( tribe_is_month() && !is_tax() ) { // The Main Calendar Page
    		return '**PUT MAIN CALENDAR PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_month() && is_tax() ) { // Calendar Category Pages
    		return single_term_title('', false) . '**PUT CALENDAR CATEGORY PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_event() && !tribe_is_day() && !is_single() ) { // The Main Events List
    		return '**PUT EVENTS LIST PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_day() ) { // Single Event Days
    		return 'Events on: ' . date('F j, Y', strtotime($wp_query->query_vars['eventDate'])) . ' **PUT SINGLE EVENT DAY META DESCRIPTION HERE**';
    	} elseif( tribe_is_venue() ) { // Single Venues
    		return '**PUT VENUE PAGE META DESCRIPTION HERE**';
    	} else {
    		return $description;
    	}
    }

    This code was edited from code to add titles to the events pages found here :
    https://gist.github.com/jo-snips/3710617

    https://wordpress.org/plugins/the-events-calendar/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Brook

    (@brook-tribe)

    Modern Tribe Support Rep

    That is awesome! Thanks for sharing mredinius. 🙂

    – Brook

    You are welcome!

    It does need a tweak to not overwrite the title and description of the home page. The code below takes care of it :

    add_filter('wpseo_metadesc','my_custom_description');
    function my_custom_description($description) {
    	if( tribe_is_month() && !is_tax() ) { // The Main Calendar Page
    		return '**PUT MAIN CALENDAR PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_month() && is_tax() ) { // Calendar Category Pages
    		return single_term_title('', false) . '**PUT CALENDAR CATEGORY PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_event() && !tribe_is_day() && !is_single() && !is_home() ) { // The Main Events List
    		return '**PUT EVENTS LIST PAGE META DESCRIPTION HERE**';
    	} elseif( tribe_is_day() ) { // Single Event Days
    		return 'Events on: ' . date('F j, Y', strtotime($wp_query->query_vars['eventDate'])) . ' **PUT SINGLE EVENT DAY META DESCRIPTION HERE**';
    	} elseif( tribe_is_venue() ) { // Single Venues
    		return '**PUT VENUE PAGE META DESCRIPTION HERE**';
    	} else {
    		return $description;
    	}
    }
    Brook

    (@brook-tribe)

    Modern Tribe Support Rep

    We will definitely share that with folks that need it. Cheers!

    – Brook

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add meta description to main events page when using WP SEO by Yoast’ is closed to new replies.