0

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)

0

Maybe 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.

  • Thank you for your answer. I tried but didn't worked. I got the same result without any errors – Mustafa Sep 19 at 7:23
  • Where is the apply filter in comparison to where you're adding the filter hook? Is this in a plugin or theme? – Howdy_McGee Sep 19 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.