Event Date in SEO Title

Home Forums Calendar Products Events Calendar PRO Event Date in SEO Title

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1172841
    Bradley Pirman
    Participant

    Hi there,

    We have a site that is throwing Duplicate Title SEO errors (error 200) because the client has created the same event name over and over again. We’re using Yoast SEO and rewriting titles.

    We thought about using the %%date%% variable in Yoast but it’s the post date. This will work but it’s far less than ideal. Is there a way to have the SEO meta title of events reflect the event date?

    That way we could create a structure of <event name> – <event date>. This is our ideal solution to the SEO errors.

    Thanks!
    /Bradley

    #1173232
    Nico
    Member

    Hey Bradley,

    Thanks for getting in touch with us! I’ll help you on this πŸ™‚

    Try adding the snippet below to your theme’s (or child theme’s) functions.php file:

    /* Tribe, add event date to Yoast Seo title */
    function tribe_add_date_to_title( $title ) {

    if( !class_exists('Tribe__Events__Main') || !is_singular( Tribe__Events__Main::POSTYPE ) ) return $title;

    // tribe_get_start_time docs https://theeventscalendar.com/function/tribe_get_start_time/
    return $title . ' ' . tribe_get_start_time(null);
    }

    add_filter('wpseo_title', 'tribe_add_date_to_title');

    Please let me know if this works for you,
    Best,
    Nico

    #1178016
    Bradley Pirman
    Participant

    This reply is private.

    #1178020
    Bradley Pirman
    Participant

    This reply is private.

    #1178037
    Bradley Pirman
    Participant

    I have the event start date and time working using the attached code, but now I’m also getting the following error when trying to save changes on a Yoast SEO Titles and Metas page:
    “Warning: Cannot modify header information – headers already sent by (output started at /home/carrwine/public_html/_wp/wp-content/plugins/the-events-calendar-date-in-title/the-events-calendar-date-in-title.php:29) in /home/carrwine/public_html/_wp/wp-includes/pluggable.php on line 1167”

    
    /* Tribe, add event date to Yoast Seo title */
    function tribe_add_date_to_title( $title ) {
    
    	if( !class_exists('Tribe__Events__Main') || !is_singular( Tribe__Events__Main::POSTTYPE ) ) return $title;
    
    	// tribe_get_start_time docs https://theeventscalendar.com/function/tribe_get_start_date/ 
    	return $title . ' ' . tribe_get_start_date( null, true, 'F j, Y, g:i a', null );
    }
    
    add_filter('wpseo_title', 'tribe_add_date_to_title');
    
    #1178674
    Nico
    Member

    Thanks for the follow-up Bradley πŸ™‚

    Good work spotting the typo in POSTYPE, changing that to POSTTYPE seem to be the way to go. With that change the code is working as expected in my local site.

    Can you please try to paste the code in a plain text editor and then move it to the plugin once again? Sometimes copying code directly from the forums can lead to these type of errors. I also tried to reproduce this in my local test site but was able to edit an events meta and title fields, so not sure about it.

    In case this is still an issue after doing what I suggested above please send me a screenshot of the settings you are editing that bring up the error and which line from the code is plugins/the-events-calendar-date-in-title/the-events-calendar-date-in-title.php:29.

    Best,
    Nico

    #1182178
    Bradley Pirman
    Participant

    Looks like this is working. The header issue is from a different Events Calendar plugin I created. I’ll post in a separate thread.
    Thanks!

    #1182418
    Nico
    Member

    Glad to hear Bradley πŸ™‚

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Event Date in SEO Title’ is closed to new replies.