我试图覆盖使用7主题创建的花式标题。此功能将生成7个标题:
function presscore_get_page_title() {
$title = \'\';
if ( is_page() || is_single() ) {
$title = get_the_title();
} else if ( is_search() ) {
$title = sprintf( __( \'Search Results for: %s\', \'the7mk2\' ), \'<span>\' . get_search_query() . \'</span>\' );
} else if ( is_archive() ) {
if ( is_category() ) {
$title = sprintf( __( \'Category Archives: %s\', \'the7mk2\' ), \'<span>\' . single_cat_title( \'\', false ) . \'</span>\' );
} elseif ( is_tag() ) {
$title = sprintf( __( \'Tag Archives: %s\', \'the7mk2\' ), \'<span>\' . single_tag_title( \'\', false ) . \'</span>\' );
} elseif ( is_author() ) {
the_post();
$title = sprintf( __( \'Author Archives: %s\', \'the7mk2\' ), \'<span class="vcard"><a class="url fn n" href="\' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . \'" title="\' . esc_attr( get_the_author() ) . \'" rel="me">\' . get_the_author() . \'</a></span>\' );
rewind_posts();
} elseif ( is_day() ) {
$title = sprintf( __( \'Daily Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date() . \'</span>\' );
} elseif ( is_month() ) {
$title = sprintf( __( \'Monthly Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date( \'F Y\' ) . \'</span>\' );
} elseif ( is_year() ) {
$title = sprintf( __( \'Yearly Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date( \'Y\' ) . \'</span>\' );
} else {
$title = __( \'Archives:\', \'the7mk2\' );
}
} elseif ( is_404() ) {
$title = __( \'Page not found\', \'the7mk2\' );
} else {
$title = __( \'Blog\', \'the7mk2\' );
}
return apply_filters( \'presscore_get_page_title\', $title );
}
我使用一个插件创建了一些动态页面,该插件可以查询数据库并将结果放入动态生成的页面中:每个页面都是在调用时生成的,因此不会存储在数据库中。
现在,所有页面都从插入短代码的默认页面获取标题。我需要根据生成的页面动态更改标题。
我尝试使用此函数,但它不会影响任何内容:
function presscore_get_page_title() {
$title = \'\';
if ( is_page() || is_single() ) {
$title = get_the_title();
} else if ( is_search() ) {
$title = sprintf( __( \'Search Results for: %s\', \'the7mk2\' ), \'<span>\' . get_search_query() . \'</span>\' );
} else if ( is_archive() ) {
if ( is_category() ) {
$title = sprintf( __( \'Category Archives: %s\', \'the7mk2\' ), \'<span>\' . single_cat_title( \'\', false ) . \'</span>\' );
} elseif ( is_tag() ) {
$title = sprintf( __( \'Tag Archives: %s\', \'the7mk2\' ), \'<span>\' . single_tag_title( \'\', false ) . \'</span>\' );
} elseif ( is_author() ) {
the_post();
$title = sprintf( __( \'Author Archives: %s\', \'the7mk2\' ), \'<span class="vcard"><a class="url fn n" href="\' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . \'" title="\' . esc_attr( get_the_author() ) . \'" rel="me">\' . get_the_author() . \'</a></span>\' );
rewind_posts();
} elseif ( is_day() ) {
$title = sprintf( __( \'Daily Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date() . \'</span>\' );
} elseif ( is_month() ) {
$title = sprintf( __( \'Monthly Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date( \'F Y\' ) . \'</span>\' );
} elseif ( is_year() ) {
$title = sprintf( __( \'Yearly Archives: %s\', \'the7mk2\' ), \'<span>\' . get_the_date( \'Y\' ) . \'</span>\' );
} else {
$title = __( \'Archives:\', \'the7mk2\' );
}
} elseif ( is_404() ) {
$title = __( \'Page not found\', \'the7mk2\' );
} elseif( is_page_template( \'accomodations.php\' ) ){
$title = __( \'Test\', \'the7mk2\' );
} else {
$title = __( \'Blog\', \'the7mk2\' );
}
return apply_filters( \'presscore_get_page_title\', $title );
}
有什么建议吗?