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 ?
If you want to check
post_type
archive page then you have to useis_post_type_archive()
and if you want to check the archive page of custompost_type
category then you have to useis_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!
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"); ?>
<?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'>";
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.