In WordPress, the links to author profile pages are generated by default and depend on the permalink structure. If you want to get the link to an author’s profile page (e.g., the author.php
file), you can use the following methods:
1. Using the get_author_posts_url()
function
The get_author_posts_url()
function returns the URL to the author’s page:
<?php
$author_id = 1; // Author ID
$author_url = get_author_posts_url($author_id);
echo $author_url;
?>
2. Using the global $author
object
If you’re inside the WordPress loop or displaying information about the author of a post, you can use the global $post
object:
<?php
global $post;
$author_url = get_author_posts_url($post->post_author);
echo $author_url;
?>
Both methods will give you the URL to the author’s page where you can display their posts or other related content.