我有多个单episodes.php single-movies.php single-seasons.php single-tvshows.php我希望他们每个人都有自定义元标签标题和描述我不擅长编码所以我正在寻找谷歌的解决方案,我发现了这个
要在每个帖子上将描述设置为唯一,您可以添加条件标记查询,询问“如果这是一个帖子视图,请显示您选择的帖子说明;如果这是一个多帖子视图,请显示博客名称和说明。“条件标签查询如下所示:
<meta name="description" content="<?php if ( is_single() ) { single_post_title('', true); } else { echo "description of your choice"; } ?>" />
我如何在标题中填充此代码,以便每个单独采用自定义元标记
答案 0 :(得分:0)
您可以使用is_single()
部分中的<head>
功能。
来源:https://developer.wordpress.org/reference/functions/is_single/ 这是一个有效的演示:https://developer.wordpress.org/reference/functions/is_single/#comment-496
is_single('my-slug');
// When the Post with post_name (slug) of "my-slug" is being displayed.
为了帖子的目的,我在下面为你编码。
<?php
// Variables
$my_custom_title = '';
$my_custom_description = '';
if(is_single('episodes')) {
$my_custom_title = 'Episodes';
$my_custom_description = 'My custom description for episodes.';
}
elseif(is_single('seasons')) {
$my_custom_title = 'Seasons';
$my_custom_description = 'My custom description for seasons.';
}
elseif(is_single('tvshows')) {
$my_custom_title = 'TV Shows';
$my_custom_description = 'My custom description for TV shows.';
}
else {
$my_custom_title = get_bloginfo('name');
$my_custom_description = get_bloginfo('description');
}
?>
<title><?php echo $my_custom_title; ?></title>
<meta name="description" content="<?php echo $my_custom_description; ?>" />
详细了解get_bloginfo()
:https://developer.wordpress.org/reference/functions/get_bloginfo/