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?

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
   }
}
?>
  • 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? – The WP Intermediate Oct 17 '16 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? – The WP Intermediate Oct 17 '16 at 2:04
  • @Champion I highly recommend to leave the tags out of your header and let Yoast SEO plugin do the rest. – Robbert Oct 17 '16 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 Oct 17 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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