My homepage setting is "Display the latest post's" and I have the number set to 1. So my homepage show's my latest post.
I have YOAST plugin setting the title in homepage for now. I would like to customize the home page's title as below...
I would prefer to edit code and achieve this instead of a plugin. I did a bit of searching and I did not get much help. Here is what I have now... I tried putting this into the child theme's functions.php and it did not change anything...
add_filter('wpseo_title', 'filter_keral_wpseo_title');
function filter_keral_wpseo_title($title) {
if( is_front_page() ) {
$recent = get_posts(array(
'author'=>1,
'orderby'=>'date',
'order'=>'desc',
'numberposts'=>1
));
if( $recent ){
$title = get_the_title($recent[0]->ID);
}
}
return $title;
}
Thanks for your time!
My homepage setting is "Display the latest post's" and I have the number set to 1. So my homepage show's my latest post.
I have YOAST plugin setting the title in homepage for now. I would like to customize the home page's title as below...
I would prefer to edit code and achieve this instead of a plugin. I did a bit of searching and I did not get much help. Here is what I have now... I tried putting this into the child theme's functions.php and it did not change anything...
add_filter('wpseo_title', 'filter_keral_wpseo_title');
function filter_keral_wpseo_title($title) {
if( is_front_page() ) {
$recent = get_posts(array(
'author'=>1,
'orderby'=>'date',
'order'=>'desc',
'numberposts'=>1
));
if( $recent ){
$title = get_the_title($recent[0]->ID);
}
}
return $title;
}
Thanks for your time!
Actually the above code (reposted below) worked perfectly. Guess it was a cache issue that it did not get reflected. Thanks for your time!
add_filter('wpseo_title', 'filter_keral_wpseo_title');
function filter_keral_wpseo_title($title) {
if( is_front_page() ) {
$recent = get_posts(array(
'author'=>1,
'orderby'=>'date',
'order'=>'desc',
'numberposts'=>1
));
if( $recent ){
$title = get_the_title($recent[0]->ID);
}
}
return $title;
}