• Resolved xroox

    (@xroox)


    Hi! I’m trying to re-use my Yoast meta description into a structured data description field by adding it to my page template.

    I found online someone said I could get the Yoast meta using:

    get_post_meta($post->ID, ‘_yoast_wpseo_metadesc’, true);

    However, when I add this to my echo statement, which looks like so:

    $yoast_meta = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true);
    
    function my_service_template_footer_data() {
        echo "<script type='application/ld+json'>
    {
        '@context': 'https://schema.org/',
        '@type': 'Service',
        'serviceType': ' " . get_the_title() . " ',
        'description': ' " . $yoast_meta . " ',
        'provider': {
          '@type': 'LocalBusiness',
         ...ETC...

    I get the following error from WP DEBUG:

    Parse error: syntax error, unexpected ‘.’ in /home/x/y/public_html/wp-content/themes/twentytwentyone-child/functions.php on line 99

    Any tips to get this working? Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @xroox,

    The best way to get data from Yoast SEO is to use the provided APIs like the Yoast Surfaces API and the Yoast Schema API.

    For example, to get the meta description for any post, you can use the following:
    $yoast_meta = YoastSEO()->meta->for_current_page()->description;.

    If you’d like Yoast SEO to add LocalBusiness data to your schema data for you instead of adding custom code, that’s available as a feature in the Local SEO premium add-on.

    Plugin Support devnihil

    (@devnihil)

    We are going ahead and marking this issue as resolved due to inactivity. If you require any further assistance please create a new issue.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to re-use Yoast meta in page template?’ is closed to new replies.