使用wpseo_opengraph_title
过滤器:
function wpse_187763_wpseo_opengraph_title( $title ) {
if ( is_singular() && $post = get_queried_object() ) {
if ( $_title = get_post_meta( $post->ID, \'custom_field_key\', true ) )
$title = $_title; // Override title with custom meta title
}
return $title;
}
add_filter( \'wpseo_opengraph_title\', \'wpse_187763_wpseo_opengraph_title\' );
Update: 单曲
=
是有意的,因为我们正在分配值&;同时测试表达式。换句话说,这与:
$_title = get_post_meta( $post->ID, \'custom_field_key\', true );
if ( $_title )
$title = $_title;