0

I use get_the_archive_title hook to add a link to my blog tags and categories archives pages.

https://developer.wordpress.org/reference/hooks/get_the_archive_title/

I just get the title and filter it to include it into an title like this: enter image description here

but it also changes the browser tab title =( enter image description here

How can I avoid this?? Thank you!

  • Quick & Dirty: use debug_backtrace to see who's calling that filter? – janh Nov 13 '17 at 9:17
  • yup, called by blog-header.php, any option to return $content when called from there so I don't filter it? – Zeko Nov 13 '17 at 11:13
0

You could do something like this to see where it was called from:

add_filter("get_the_archive_title", function($val) {
     $backtrace = debug_backtrace();
     foreach($backtrace as $level) {
         if(array_key_exists("file", $level) && preg_match("!that-file\.php$!",  $level["file"]) && array_key_exists("function", $level) && $level["function"] == "get_the_archive_title" ) {
             return "works: $val";
         }
     }
     return "test: $val";
 }, 10, 1);

You'll have to adapt the regexp ("that-file.php") to your needs, and potentially check for another function if it's not done with get_the_archive_title().

| improve this answer | |

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.