admin管理员组文章数量:1130349
I'm trying to hook a page title using is_page() and its ID 1637 along with two taxonomies serie and area. But I can't get it to work. am I missing something
code:
add_filter( 'wp_title', 'new_listing_title', 10, 1 );
function new_listing_title($title)
{
if ( is_page('1637') && $id = get_queried_object_id() )
{
$locations = get_query_var('area');
$location = get_term_by('slug', $locations, 'area');
$models = get_query_var('serie');
$model = get_term_by('slug', $models, 'serie');
$title = '';
if($model && $model) $title .= $model->name . ' Used';
else $title .= 'Used';
$title .= ' Cars For Sale';
if($location && $location) $title .= ' In ' . $location->name;
return $title;
}
return $title;
}
edit : When I use this however, it does actually display the title in this particular manner(code below). How do I combine $wp_query->query_vars[] along with my code above?
global $wp_query;
echo 'Car : ' . $wp_query->query_vars['serie'];
echo '<br />';
echo 'Area : ' . $wp_query->query_vars['area'];
I'm trying to hook a page title using is_page() and its ID 1637 along with two taxonomies serie and area. But I can't get it to work. am I missing something
code:
add_filter( 'wp_title', 'new_listing_title', 10, 1 );
function new_listing_title($title)
{
if ( is_page('1637') && $id = get_queried_object_id() )
{
$locations = get_query_var('area');
$location = get_term_by('slug', $locations, 'area');
$models = get_query_var('serie');
$model = get_term_by('slug', $models, 'serie');
$title = '';
if($model && $model) $title .= $model->name . ' Used';
else $title .= 'Used';
$title .= ' Cars For Sale';
if($location && $location) $title .= ' In ' . $location->name;
return $title;
}
return $title;
}
edit : When I use this however, it does actually display the title in this particular manner(code below). How do I combine $wp_query->query_vars[] along with my code above?
global $wp_query;
echo 'Car : ' . $wp_query->query_vars['serie'];
echo '<br />';
echo 'Area : ' . $wp_query->query_vars['area'];
本文标签: How to filter a page title with custom taxonomies
版权声明:本文标题:How to filter a page title with custom taxonomies 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749133831a2321032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论