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('t

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 1
Add a comment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745148796a4613769.html

相关推荐

  • 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('t

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信