Adding date info into SEO Meta Description

Home Forums Calendar Products Events Calendar PRO Adding date info into SEO Meta Description

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1387871
    Keith O Reilly
    Participant

    Hello, I was wondering if it is possible to add the date field into the Yoast SEO description text using some code edit?

    I have managed to get it into the Title using this method

    Event Date in SEO Title

    But I also need some date info in the description text to avoid duplicate descriptions.

    Any ideas?

    #1389394
    Victor
    Member

    Hi Keith!

    Thanks for reaching out to us! Let me try to help you with this topic.

    I think you could modify the snippet from that other tread to use the ‘wpseo_metadesc’ filter instead of ‘wpseo_title’ and modify the meta description to add the date in it.

    I hope that helps. Let me know if you have any follow up questions.

    Best,
    Victor

    #1389916
    Keith O Reilly
    Participant

    Hi Victor, Thanks for your advice,

    I am already using that snippet to add the date into the Meta Title, so I would need to edit that code to add the date to the description also? I tried adding afer wpseo_title but it gave me an error. How do I add it so the date appears in the Meta Title and Meta description?

    
    /* 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, 'M,j,Y', null );
    }
     
    add_filter('wpseo_title', 'wpseo_metadesc', 'tribe_add_date_to_title');
    

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wpseo_metadesc’ not found or invalid function name in /home2/gaybarce/public_html/gayberlin4u/wp-includes/class-wp-hook.php on line 298

    #1389918
    Keith O Reilly
    Participant

    Hello,

    Sorry, I am not a programmer, but following the logic of the Title code, I changed it and added it as two separate lines, so I have the Title code and then added this for the Description code

    /* Tribe, add event date to Yoast Seo title */
    function tribe_add_date_to_metadesc( $metadesc ) {
     
        if( !class_exists('Tribe__Events__Main') || !is_singular( Tribe__Events__Main::POSTTYPE ) ) return $metadesc;
     
        // tribe_get_start_time docs https://theeventscalendar.com/function/tribe_get_start_date/ 
        return $metadesc . ' ' . tribe_get_start_date( null, true, 'M,j,Y', null );
    }
     
    add_filter('wpseo_metadesc', 'tribe_add_date_to_title');

    It is working, but I am not sure if this is the most efficient way of doing it?

    #1390650
    Victor
    Member

    Hi Keith!

    You are using the tribe_add_date_to_title function to pass into the wpseo_metadesc filter, but you are defining the tribe_add_date_to_metadesc function. It might be working because I guess you have previously declared the tribe_add_date_to_title function.

    For both, the title and description you could use the following snippet:

    /* 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, 'M,j,Y', null );
    }
    add_filter('wpseo_title', 'tribe_add_date_to_title');
    /* Tribe, add event date to Yoast Seo Description */
    function tribe_add_date_to_metadesc( $metadesc ) {
      if( !class_exists('Tribe__Events__Main') || !is_singular( Tribe__Events__Main::POSTTYPE ) ) return $metadesc;
        // tribe_get_start_time docs https://theeventscalendar.com/function/tribe_get_start_date/
        return $metadesc . ' ' . tribe_get_start_date( null, true, 'M,j,Y', null );
    }
    add_filter('wpseo_metadesc', 'tribe_add_date_to_metadesc');

    Please give it a try and see if it works for you.

    Best,
    Victor

    #1390683
    Keith O Reilly
    Participant

    Yes, that seems to be working. Thanks for your assistance.

    #1390711
    Victor
    Member

    Glad to be of help! 🙂

    Thanks for following up to let me know it works for you.

    I’ll close this now but feel free to open a new topic if anything comes up and we’ll be happy to help.

    Best,
    Victor

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Adding date info into SEO Meta Description’ is closed to new replies.