我正在为我的博客网站使用 Rank Math SEO WordPress 插件。我在我的 WordPress 主题和自定义帖子标签字段中使用自定义帖子类型,对于常规帖子排名数学,将元标签添加到
wp_head
,如下所示:<meta property="article:tag" content="TAG_TEXT_HERE">
,对于每个常规帖子标签。
但是当我在自定义帖子类型标签字段中插入自定义标签时,Rank Math 无法检测到这些自定义标签。
您能帮我吗?如何为
<meta property="article:tag" content="TAG_TEXT_HERE">
内的 wp_head
标签内的每个自定义标签添加 <head></head>
?
你。可以使用以下内容,将代码中的 'custom_post_type' 替换为您的自定义帖子类型 slug,并将
wp_strip_all_tags($post->post_excerpt)
替换为您要在此 <meta>
标签中显示的 content:
add_action('wp_head', 'custom_post_type_rank_math_meta_tag', 1);
function custom_post_type_rank_math_meta_tag() {
global $post, $post_type;
// Replace 'custom_post_type' with your custom post type slug
if ( $post_type === 'custom_post_type' ) {
// Replace with the desired content
$content = wp_strip_all_tags($post->post_excerpt);
echo'<meta property="article:tag" content="'.$post_type.'">';
}
}
代码位于子主题的functions.php 文件中(或插件中)。已测试并有效。