Changing title using filter not working with argument

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)

Read more here:: Changing title using filter not working with argument

Leave a Reply

Your email address will not be published. Required fields are marked *