我正在使用创建自定义页面的wordpress主题。
但是,当使用SEO Yoast制作自定义标题和元描述时,所有自定义页面都具有与index.php(主页)相同的标题标签。这显然是谷歌网站管理员工具的一面红旗。
add_action('theme_query', 'theme_page_query');
function theme_page_query() {
global $wp_query;
$act = get_query_var( 'act' );
if ($act == 'new-wallpapers') {
query_posts('orderby=post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'popular-wallpapers') {
query_posts('meta_key=theme_hit_download&orderby=meta_value_num post_date&order=DESC&paged='.get_query_var('page'));
} elseif ($act == 'random-wallpapers') {
query_posts('orderby=rand&paged='.get_query_var('page'));
} elseif ($act == 'recent-downloads') {
query_posts('meta_key=theme_hit_download_time&orderby=meta_value&order=DESC&paged='.get_query_var('page'));
}
}
function theme_page_title($title) {
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' )));
}
return $title;
}
add_filter( 'wp_title', 'theme_wp_title', 10, 2 );
function theme_wp_title( $title, $sep ) {
global $paged, $page, $wp_query;
if ( is_feed() ) {
return $title;
}
if (in_array(get_query_var( 'act' ), array(
'new-wallpapers',
'popular-wallpapers',
'random-wallpapers',
'recent-downloads',
))) {
$title = ucwords(str_replace('-', ' ', get_query_var( 'act' ))) . " {$sep} ";
}
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'theme' ), max( $paged, $page ) );
}
return $title;
}
我尝试过搜索,但是我找不到一步一步的指南,而且我不擅长PHP。任何帮助将不胜感激。
答案 0 :(得分:0)
您可以通过
分三个步骤完成此操作 1。Add a new input box to the admin pages for creating and editing new Posts/Pages
2。Save the the value of that input box when that Post/Page is saved
3。Echo out a new title as part of the wp_head() function
here是详细解释。希望它有所帮助..谢谢