the_author()
filter hook can be used to modify the output of the_author()
. When using the hook, is it possible to know which PHP file generates which call to the_author()
?
For example, say I have this custom function attached to the_author()
filter hook, which modifies the_author()
output:
add_filter("the_author", "change_author");
function change_author($author) {
$author = "NEW AUTHOR!";
return $author;
}
When I load my page, I can see this change occur in 5 separate sections:
- Once in the header (from file header.php).
- Twice in the body (from file page.php).
- Twice in the footer (from file footer.php).
Inside my function change_author()
, is there any way to know which PHP file is currently making the call to the_author()
?
My motivation for asking is because I'd like to change the author for only certain sections, i.e. only when the_author()
is called from a specific file (my_file.php). For all other instances of the the_author()
I want to leave the output unmolested. I'm just wondering if that's possible to accomplish using the_author()
filter hook.
my_file.php
instead ofthe_author
? What you're asking for is not a trivial thing, and is beyond most developers capabilities, the result may not be exactly what you want either, specifically you'll need the reflection API to be available. I can guarantee there are better ways to solve your problem of displaying different things on your template, such as using a custom functionthe_author()
. I want to return a blank string forthe_authoer()
in each of these cases. Does that make sense?