I have following problem in Wordpress. I have this code in function.php which should make posts title on frontend from Yoast SEO title. Code works, however it has also impact on pages.
function set_my_seo_title($title, $id)
{
global $post;
$seo_title=get_post_meta($id, '_yoast_wpseo_title', true);
return ((!empty($seo_title)&&$post->post_type=='post') ? $seo_title : $title);
}
add_filter('the_title', 'set_my_seo_title', 15, 2);
The problem is with condition post_type=='post'
. It looks like there is some bug in Wordpress, but may be I am doing something wrong.
Important: I have to admit I am not good developer. This code is from other question. If you know solution for this please post your full code variant. Thank you in advance.