Using WordPress ‘get_the_author_url()’ PHP function

The get_the_author_url() WordPress PHP function retrieves the URL to the home page of the author of the current post.

Usage

get_the_author_url();

Custom Example:

Input:

echo 'Author URL: ' . get_the_author_url();

Output:

Author URL: https://example.com/author/johndoe

Parameters

  • None

More information

See WordPress Developer Resources: get_the_author_url()

Examples

Display Author URL in a Post

Display the author’s URL at the bottom of each post.

function display_author_url() {
    echo 'Author URL: ' . get_the_author_url();
}
add_action('the_content', 'display_author_url');

Adding Author URL to Author Bio

Add the author’s URL to their bio.

function author_bio_with_url() {
    $author_bio = get_the_author_meta('description');
    $author_url = get_the_author_url();
    echo $author_bio . ' Visit the author\'s page: <a href="' . $author_url . '">' . $author_url . '</a>';
}
add_filter('get_the_author_description', 'author_bio_with_url');

Creating a Custom Author Box

Create a custom author box that includes the author’s URL.

function custom_author_box() {
    $author_name = get_the_author();
    $author_url = get_the_author_url();
    echo '<div class="author-box">';
    echo '<h3>About ' . $author_name . '</h3>';
    echo '<p><a href="' . $author_url . '">' . $author_url . '</a></p>';
    echo '</div>';
}
add_action('the_content', 'custom_author_box');

Displaying Author URL in a Custom Loop

Display the author’s URL in a custom loop.

$args = array(
    'post_type' => 'post',
    'posts_per_page' => 5
);

$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        echo '<h2>' . get_the_title() . '</h2>';
        echo '<p>Author URL: <a href="' . get_the_author_url() . '">' . get_the_author_url() . '</a></p>';
    }
}
wp_reset_postdata();

Show Author URL in a Custom Widget

Create a custom widget that displays the author’s URL.

class Author_URL_Widget extends WP_Widget {
    public function __construct() {
        parent::__construct(
            'author_url_widget',
            'Author URL Widget',
            array('description' => 'Displays author URL of the current post.')
        );
    }

    public function widget($args, $instance) {
        echo $args['before_widget'];
        echo 'Author URL: <a href="' . get_the_author_url() . '">' . get_the_author_url() . '</a>';
        echo $args['after_widget'];
    }
}
add_action('widgets_init', function() {
    register_widget('Author_URL_Widget');
});