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

2 Answers 2

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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