zourbuth
zourbuth

Reputation: 908

Add filter to the_title only for the_title function

Since the_title() and the_title_attribute() function use the same function get_the_title() to retrieve the title, is there a way to add the_title filter only for the_title() function?

Upvotes: 0

Views: 1346

Answers (2)

cweb24
cweb24

Reputation: 1

Worked for me.

add_filter('the_title', 'somefilter');
function somefilter($title)
{
     $tr=debug_backtrace();
     $out='';
     foreach ($tr as $v){
         if (strpos($v['function'], 'title')) {
             $out.=$v['function'];
         }
    }
    if ($out!='get_the_titlethe_title') {
         return $title;
    }
    /** some filtering of the_title()
    but not get_the_title() can be placed below **/
}

Upvotes: 0

C. E.
C. E.

Reputation: 10607

No, there is no way to do that since neither the_title nor the_title_attribute offer any filters. Like you say, they call get_the_title which is where the the_title filter is. But you could easily copy the code of the_title and make your own version of it.

Upvotes: 1

Related Questions