1

I am just working on filter titles in pages and posts and everything works as expected but when I view the single.php whereas it shows the actual post as should be, the function hook filter i am working on inside functions.php of my plugin is filtering every title of each post of my blog, I was expecting to filter just the title of the current post:

add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((in_the_loop())){ 
      /**/
    }    
}

any help is grateful.

Thanks ;)

4

2 回答 2

0
add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((some condition true)){ 
     $add_this = 'some string';
     $new_title = $title.' '.$add_this;
      return $new_title;
    }   

      return $title; 
}

当您查看任何帖子时,它会通过 single.php 显示,因此每个帖子在您查看时都会成为当前帖子

于 2013-11-05T17:46:50.140 回答
0

我现在明白,对于过滤器标题挂钩,从 single.php 查看单个帖子与查看整个博客相同。是否有一种过滤方法以仅在 single.php 中检索当前帖子的标题?我确实尝试过像这样的“get_the_title(get_the_ID())”,但显然我不能嵌套它。

add_filter( 'the_title', 'ta_modified_post_title');
function ta_modified_post_title ($title) { 
    if((in_the_loop())){ 
      if(is_single()){
        $title=get_the_title(get_the_ID());
      }
    }    
}
于 2013-11-06T20:28:40.167 回答