I'm trying to change my custom page's title and I'm able to do this with this function:
add_filter('the_title','change_title');
function change_title($data){
global $post;
return 'Page ID ' . $post->ID;
}
and I'm calling the filter:
apply_filters('the_title', $response->data->name);
This works fine but when I try to use the $data
the page title returning to default name. I mean if change the filter to this:
add_filter('the_title','change_title');
function change_title($data){
global $post;
return 'Page ID ' . $data;
}
the title returning to default title. Why I can't set a dynamic title? Also I'm pretty sure that I'm passing a string. (BTW I'm using Hestia theme)
I'm trying to change my custom page's title and I'm able to do this with this function:
add_filter('the_title','change_title');
function change_title($data){
global $post;
return 'Page ID ' . $post->ID;
}
and I'm calling the filter:
apply_filters('the_title', $response->data->name);
This works fine but when I try to use the $data
the page title returning to default name. I mean if change the filter to this:
add_filter('the_title','change_title');
function change_title($data){
global $post;
return 'Page ID ' . $data;
}
the title returning to default title. Why I can't set a dynamic title? Also I'm pretty sure that I'm passing a string. (BTW I'm using Hestia theme)
Share Improve this question asked Sep 18, 2019 at 15:32 MustafaMustafa 11 Answer
Reset to default 0Maybe you can add a higher priority to your filter as the 3rd parameter of the hook:
/**
* Modify the data
*
* @param String $data
*
* @return String $data
*/
function change_title( $data ) {
global $post;
return 'Page ID ' . $data;
}
add_filter( 'the_title', 'change_title', 15 );
The default priority is 10 so it could be that a later filter is overwriting what you have.