In WordPress I have a page template called designers.php
.
When loading, it reads the slug
to get a uniqe ID, then calls the DB to retrieve designer information.
I want to use this information to alter the page title, using the designer name in the title tag.
I’ve tried using the add_filter
in my designers.php
file, but it’s not working:
add_filter('wp_title', 'set_page_title');
function set_page_title($title) {
global $brand;
return 'Designer '.$brand['name'].' - '.get_bloginfo('name');
}
I’m, guessing the add_filter
must either be located inside a plugin or in functions.php
file.
How can I achieve what I’m trying to do?
UPDATE
The function is never fired as long as I use wp_title
. If I change it to init
(for testing), the function is fired.
So why does the add_filter
nor work for wp_title
?
You are almost right. The filter must reside in function.php, and is called to modify the title. You can add the filter conditionally. Use this function is_page_template() to determine if wordpress is rendering your template
Try to modify your function like this:
First of all
add_filter
must either be located inside a plugin or infunctions.php
file.Then, maybe you have to set the priority for the filter :
And check the
<title>
meta in yourheader.php
theme.