Every WordPress page can be described as having two titles:
The page/post title, which is displayed within the page/post via the
the_title()
function callThe html
<title></title>
tag that displays the title on top of the browser
I am writing a plugin which at one point should change the title of a page dynamically (well, it should change both titles described above).
So, for step 1 above, I found multiple solutions on Stack Overflow (such as this or this). Those are great for only step 1 above.
For step 2, I found this solution; in a nutshell, this is how it works:
add_filter('wp_title', 'change_page_title');
function change_page_title ($title) {
// Do some magic, and eventually modify $title then return it
return $title;
}
But the suggested solution is not working for me; and by not working I mean that the filter is not calling the associated function. I am not sure what the problem is; is it because this filter is being called from within the plugin not the theme? (Just FYI, I do not have access to the theme files, so it has to be done from within the plugin).
How can I accomplish this? How can I change the browser title of a page dynamically from within a plugin?
Thanks.