Search code examples
phphtmlwordpressgoogle-chromelighthouse

Missing meta tag in head Wordpress


Lighthouse is giving me error that I am missing viewport meta tag and description meta tag

Does not have a <meta name="viewport"> tag with width or initial-scaleNo `<meta name="viewport">` tag found

But I have both meta tags in my in header.php file

<head>
  <meta name="description" content="Description">
  <meta charset="utf-8">
  <title>My site</title>
  <?php wp_head(); ?>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

EDIT: When I inspect website in my browser I can see that the meta tags have automatically moved from tag to body tag. Don't know why

Has anyone had this issue? I've tried adding meta tags trought functions.php but no luck with that solution either. Cheers!


Solution

  • So basically I made a really silly mistake. In my page.php I head get_header() function in wrong place

    BEFORE

    <div class="w-large">
     <?php get_header(); ?>
        <?php
        while (have_posts()) : the_post();
            the_content();
        endwhile;
        ?>
    
    </div>
    
    <?php get_footer(); ?>
    

    AFTER

    <div class="w-large">
    
        <?php
        while (have_posts()) : the_post();
            the_content();
        endwhile;
        ?>
    
    </div>
    
    <?php get_footer(); ?>