[resolved] add_filter('the_author_link','...'); - does it exist? (3 posts)

  1. Gengar003
    Posted 5 years ago #

    I have a plugin that I want to change the place that users are taken to if they click an author's name.

    The obvious way to do this, I figured, would be to filter on "the_author_link," and change the link.

    However, there does not seem to be a hook for "the_author_link," - there seems to only be a hook for "the_author."

    This works, in that I can filter on "the_author," and wrap the author name in a link, and it links to where I want.

    However, what's really going on is this:

    <a href='the original the_author_link_url'>
    <a href='my new URL'>Author's Name</a>

    A link inside a link is not valid markup. Thus, while my plugin will work and behave the way I want if I use this method, I cannot make it valid HTML, XHTML, or anything.

    My question, then, is twofold:

    1. Is there, or is there not, a hook to add_filter on 'the_author_link'?

    2. If there is no such hook, how do I go about correctly implementing a change to the behavior of the_author_link(); ?

    Thank you for your time.

  2. Mark / t31os

    Posted 5 years ago #

    See wp-includes/author-template.php, there are quite a few hooks.. this one should be suited for what you want..

    add_filter( 'get_the_author_url', 'your_filter', 10, 2 );
    function your_filter( $_author_url, $_author_id ) {
    	// Do stuff - $_author_url is the given author's existing URL
    	// Leave this line, data must be returned, just do what you want with it above
    	return $_author_url;

    Hope that helps...

  3. Gengar003
    Posted 5 years ago #

    Yes, that is what I needed; thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic