skip to Main Content

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?

<?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

2

Answers


  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);
    
    Login or Signup to reply.
  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"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search