Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to show my meta description content above posts. But i don't know what function I need to call.

Resume: i want to put meta description from Yoast Seo above the posts body.

share|improve this question

closed as off-topic by Mark Kaplun, Johannes Pille, Pieter Goosen, ialocin, s_ha_dum Oct 6 at 23:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Mark Kaplun, Johannes Pille, Pieter Goosen, ialocin, s_ha_dum
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

Solution:

<?php $object = new WPSEO_Frontend();
        echo $object->metadesc( false ); ?> 
share|improve this answer
2  
Some explanations could turn this fragment into an answer. ;) –  toscho Oct 4 '12 at 22:18
    
+1 for this solution. This works like charm in and outside the loop. Thanks Ukelele. –  gurung Jan 10 at 9:31

You will want to make use of Yoast SEO's "WPSEO_Frontend" class. To display the meta description field content, you could do the following:

<?php
   if (class_exists('WPSEO_Frontend'))
   {
       echo WPSEO_Frontend::metadesc(false);
   }
?>
share|improve this answer
    
If i put your code it gives me a blank page. And if i put just "echo ..." i got this error "Fatal error: Using $this when not in object context in /home/user999/public_html/mydomain.com/wp-content/plugins/wordpress-seo/frontend‌​/class-frontend.php on line 809" –  ukelele2 Oct 3 '12 at 23:35
    
ok, let's see how you're implementing this code. I tested it and it works fine in a post loop, where the post has a Yoast SEO meta description filled in. –  Ben Oct 4 '12 at 0:04
    
I'm implementing on archives.php for categories. I'm using "Meta description template" in "Titles & Metas" option from Yoast SEO. –  ukelele2 Oct 4 '12 at 9:23
    
Fatal error: $this when not in object context in /home/..... and yes, the error occurs with the code within the loop. –  gurung Jan 10 at 9:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.