可以更改模板文件中显示的标题(例如content.php):
$custom_field = get_post_meta($post->ID, $custom_meta_key, true);
if ( is_single() ) {
the_title( \'<h1 class="entry-title">\', \'</h1>\' );
} elseif ( is_front_page() && is_home() ) {
the_title( \'<h3 class="entry-title"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\',
\' \' . $custom_field . \'</a></h3>\' );
} else {
the_title( \'<h2 class="entry-title"><a href="\' . esc_url( get_permalink() ) . \'" rel="bookmark">\',
\' \' . $custom_field . \'</a></h2>\' );
}
您还可以使用
the_title
过滤器挂钩(代码转到functions.php):
add_filter( \'the_title\', \'modify_post_title\' );
function modify_post_title( $title ) {
global $post;
//
// --- show on list and single post view
// if ( $post->post_type == \'post\' && in_the_loop() ) {
// --- show only in single post view
// if ( is_singular() && $post->post_type == \'post\' && in_the_loop() ) {
// when to apply custom field suffix
// --- when type is "post" and when it\'s not a single post view
if ( !is_singular() && $post->post_type == \'post\' && in_the_loop() ) {
// $custom_field = get_post_meta($post->ID, $custom_meta_key, true);
$title .= $custom_field;
}
return $title;
}
这取决于你想要实现什么。