The best way to go about it is using the the_title
filter. Put the following code in your functions.php
.
add_filter( 'the_title', 'wpse_64467_prefix_title', '', 2 );
function wpse_64467_prefix_title( $title, $id ){
$header_title = get_post_meta( $id, 'header_title', true );
$title = ( $header_title ) ? $header_title . ' - ' . $title : $title;
return $title;
}
Just replace header_title
with the custom field name you are using.
UPDATE:
I guess google takes what it gets in the <title>
tag in the head as the title. The above code won’t modify that. To modify the same you need to use the single_post_title
filter in the following manner.
add_filter( 'single_post_title', 'wpse_64467_prefix_wp_title', '', 2 );
function wpse_64467_prefix_wp_title( $title, $post ){
$header_title = get_post_meta( $post->ID, '_custom_text', true );
$title = ( $header_title ) ? $header_title . html_entity_decode( ' – ', ENT_QUOTES, 'UTF-8' ) . $title : $title;
return $title;
}
P.S – It would take time for the google results to reflect.