php - 在 WordPress 中为自定义帖子类型存档添加元描述

标签 php wordpress seo custom-post-type yoast

这是我的问题:
我有一个 WordPress 网站,我在其中创建了一个自定义帖子类型(名为“collections”),每个集合都有一篇文章。
我想在自定义帖子类型的存档页面中添加元描述

www.thesitename.com/collections

我在 header.php 中尝试过这个位:

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

但是源码里什么都没有...
我在 Yoast SEO 中到处都看过,但我找不到解决方案,甚至在谷歌上也找不到。 你有想法吗?

最佳答案

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';
}

附加信息但与您的问题没有直接关系。

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';
}

希望这对您有所帮助!

关于php - 在 WordPress 中为自定义帖子类型存档添加元描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42896558/

相关文章:

php - 添加 Magento 系统 URL 重写

php - WordPress - 在插件中创建操作路径

php - 在 Laravel 中创建友好的 url

php - 如何使用 ssh2 列出其他服务器中目录的文件

php - 修剪()函数: How to avoid empty string return if the argument is unset/null variable?

paypal - Woocommerce 和 PayPal Here 集成

jquery - 如何在购物车更新时更新购物车中的附加属性?

url - 如何使用 .htaccess 和多个参数制作更好的 URL?

php - 我们可以通过点击链接传递 $_POST 值吗?

php - 警告 : mysql_fetch_array(): supplied argument is not a valid MySQL result resource