I got a requirement to update the blog page title with the recent post title. I got the result using this code and its working. I am using get_header() and page title is in header file. I have different templates in theme and blog is also a template page because I am using wp as CMS.
One simple options is copy paste the header code into blog template and apply the title. Is there any other possibility to modify the title using functions or code without copy pasting complete header code into template file.
$query = new WP_Query( array ( 'orderby' => 'date', 'order' => 'DESC', 'post_type'=>'post') );
$queried_post = get_post($query->post->ID);
$title = $queried_post->post_title;
_e($title);
Yes, you can hook into the
wp_titlecallback (filter) and change it then. You then do not need to modify each theme’s template file. Your callback function then needs to return the new title: