5

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 2

13

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); 
Sign up to request clarification or add additional context in comments.

1 Comment

Do you know where I could use this in a page template? I tried adding this to page.php but nothing prints (checked on a page w a Yoast meta description on it). Thanks!
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.