skip to Main Content

Here’s my issue :
I have a WordPress site where I created a custom post type (named “collections“) with an article for each collection.
I’d like to add a meta description to the archive page of the custom post type

www.thesitename.com/collections

I have tried with this bit in header.php :

<?php
if (is_category('collections'))
{
    ?> 
    <meta name="description" content="the description">
<?php } ?>

but there’s nothing in the source code…
I have looked everywhere in Yoast SEO but I can’t find a solution, not even on google.
Do you have ideas ?

2

Answers


  1. WordPress is written in PHP, which means that HTML like that will not work by itself. It is for this reason that in most tracking codes are established by including something along the lines of <?php include_once("analytics.php"); ?>

    In your case, you would have to echo any HTML elements like this. Like so:

      <?php if (is_category('collections')) {
    
        echo"<meta name='description' content='the description'>";
    
         }
      ?>
    
    Login or Signup to reply.
  2. If you want to check post_type archive page then you have to use
    is_post_type_archive() and if you want to check the archive page of
    custom post_type category then you have to use is_tax()

    if (is_post_type_archive('collections'))
    {
        echo 'This is the collections post_type archive page';
    }
    

    Addition info but not directly related to your question.

    if (is_tax('collections_cat', 'cat-1'))//<-- Replace it with your taxonomy, term name
    {
        echo 'This is the collections post_type, category cat 1 archive page';
    }
    

    Hope this helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search