4 comments

  1. You do not need to add Yoast if you only want to add meta tags to the homepage. Just some minor editing will save you on performance.

    You can use the is_home() function.

    Insert this to your header.php:

    <?php if (is_home()) { ?>
     <meta name="description" content="Your description for homepage..." />
    <?php } else { ?>
     <meta name="description" content="Description for other pages..." /> 
    <?php } ?>
    
  2. You can also do by this

     <?php
    the_post();
    if (  is_home()  ) { ?>
    <meta name="description" content="YOUR DESCRIPTION" />
    <?php } elseif (is_single()) { ?>
    <meta name="description" content="<?php the_excerpt(); ?>" />
    <?php } ?>
    

    this will set different description for home and other.

  3. I had the same issue, and since this post is one of the first results that comes up in Google, I wanted to share the solution that I found.

    The code that Christine provides is good, but the problem is that you shouldn’t generally edit the header.php file directly, since your changes would be erased when you update the theme.

    The solution is to insert the code into your own plugin, and to use an action hook in order to insert the description into the header:

    <?php    
    function add_meta_home() { 
        if (is_home() || is_front_page()) { ?>
            <meta name="description" content="Lorem ipsum dolor sit amet."/>
            <?php
            }
        }
    add_action('wp_head', 'add_meta_home');
    ?>
    

    The use of (is_home() || is_front_page()) ensures that the meta description displays for your website’s homepage, regardless of how it’s configured.

Comments are closed.