the_author_link() - new window

by S. Wannsee   Last Updated July 17, 2017 10:08 AM

I need an extra pair of eyes on this. I have customized a block of code in a function of a commercial theme, which is the following code:

    <div class="author-description">
        <h5><span class="fn"><?php the_author_link(); ?></span></h5>
        <p class="note"><?php the_author_meta( 'description', $id ); ?></p>
        <?php csco_post_author_social_accounts( $id ); ?>

There's the_author_link() in it, which states either the name of the user, or the link to the website of the user, which can be filled in the admin users profile. The the_author_link() does not accept any parameters, according to the Codex.

I would like this function to open the link in a new window. Do I need to break the function down? Any help is appreciated!

Tags : author links

Answers 2

Sadly, this is one part where WordPress does not allow customization via filter or action, as you can see in the source code for that function.

However, you can copy that code and make it your own

function wpse_get_author_link_target_blank() {
    if ( get_the_author_meta('url') ) {
        return sprintf( '<a href="%1$s" title="%2$s" rel="author external" target="_blank">%3$s</a>',
        // added this part -------------------------------------------------^
            esc_url( get_the_author_meta('url') ),
            /* translators: %s: author's display name */
            esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), get_the_author() ) ),
    } else {
        return get_the_author();

And use it like so

<h5><span class="fn"><?php echo wpse_get_author_link_target_blank(); ?></span></h5>
July 17, 2017 09:39 AM

Yes, you have to get the url by user's meta:

if ( get_the_author_meta('url') ) {
    // Author has website url
    $author_url = get_the_author_meta('url');
} else {
    // Author doesn't have website url, so get Author Posts Page
    $author_url = get_author_posts_url( get_the_author_meta('ID') );
<a href="<?php echo $author_url; ?>" target="_blank">Author's website</a>
July 17, 2017 09:44 AM

Related Questions

How to show author page link

Updated June 04, 2017 00:08 AM

All Posts Linking to Author Posts directly

Updated January 27, 2017 14:03 PM

How to manage the links of a new taxonomy

Updated December 21, 2017 23:08 PM