0

How to write this Head section thing correctly in Wordpress.

<meta name="author" content="The Zebra Team">
<meta name="description" content="The Zebra Team">

I was doing it like this -

<meta name="author" content="<?php the_author(); ?>" >
<meta name="description" content="<?php the_content(); ?>" > 

But then it was not showing me anything in the head section. I think I am doing it correctly then what is the issue?

2
  • Read this Meta Tags in WordPress or Adding meta tags without plugin
    – Anish
    Commented Oct 16, 2016 at 18:55
  • So you want to say that Wordpres sis unable to read this → <meta name="author" content="<?php the_author(); ?>" > <meta name="description" content="<?php the_content(); ?>" >
    – WordCent
    Commented Oct 16, 2016 at 18:59

1 Answer 1

1

I think you have to check if the loaded page is a post, and use the Wordpress loop to get the right data.

<?php 
if ( have_posts() ) {
   while ( have_posts() ) {
      the_post(); ?>
      <meta name="author" content="<?php the_author(); ?>" >
      <meta name="description" content="<?php the_content(); ?>" >
   <?php
   }
}
?>
4
  • Thanks. I believe that this should work. I have a question what is the better way to do this. Leave it empty I mean completely remove this part → <meta name="author" content="The Zebra Team"> <meta name="description" content="The Zebra Team"> and then plugins like Yoast Seo Plugin do the needfull. Is that a better way?
    – WordCent
    Commented Oct 17, 2016 at 1:53
  • In the meanwhile, I was searching many other blogs and find that some people suggesting to do it like this → <meta name="description" content="<?php bloginfo('description'); ?>" /> Which one is a better option or a better practice to write things in Wordpress?
    – WordCent
    Commented Oct 17, 2016 at 2:04
  • @Champion I highly recommend to leave the tags out of your header and let Yoast SEO plugin do the rest.
    – Robbert
    Commented Oct 17, 2016 at 12:08
  • @Champion the_content() returns the content of a post. bloginfo('description') returns the "slogan" (added under settings -> general) of your website. These two are total different things.
    – Robbert
    Commented Oct 17, 2016 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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