How can I Get Yoast Meta from Post instead of WordPress Meta?

i’m building a WordPress Theme and we will work with Yoast do build all the SEO.

So, I would like to know how can I get at index.php/category.php and in other pages the Yoast Meta from the post instead of the normal WordPress Meta?

Read More
<?php echo substr(strip_tags($post->post_content), 0, 100);?>

this is how I get the 100 first characters from the post, So, I need to get the first 100 from Yoast SEO Meta Description!

Thx

Related posts

2 comments

  1. What exactly is the problem? This will do the trick just fine.

    echo substr(get_post_meta($post->ID, '_yoast_wpseo_metadesc', true), 0, 100);
    
  2. Add the code in the header.php.

    <meta name="description" content="<?php echo substr(get_post_meta(isset($post->ID), '_yoast_wpseo_metadesc', true), 0, 100);?>" />

    But the Value $post->ID must by inside the isset function

    $post->ID is in the isset function, isset($post->ID)

    Is no Post ID available you get this error “Trying to get property ‘ID’ of non-object”

Comments are closed.