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?


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>
  • 1
    I've added <?php the_author();?> to the <h5> to complete the code! <h5><span class="fn"><a href="<?php echo $author_url; ?>" target="_blank"><?php the_author();?></a></span></h5> – S. Wannsee Jul 17 '17 at 11:21

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>
  • 1
    Rewriting the default function works also fine! Thnx for your help Kero. – S. Wannsee Jul 17 '17 at 11:23

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.