WordPress: How to Add a Dynamic Edit Author Link to Your Theme Template

Adding an About the Author section to your WordPress posts helps personalize your site and connect readers with your writers. You can easily display the author’s name, website, and bio, and even include a special Edit Author Profile link that appears only to users with administrative or editorial permissions.
This tutorial explains the code step-by-step so you can understand exactly how it works and adapt it for your theme.
Displaying the Author Information
Open your theme’s single.php file or the template part that appears beneath each post. It may look like this code:
<?php
$author_id = get_the_author_meta('ID');
$author_url = get_the_author_meta('user_url');
$author_description = get_the_author_meta('description');
?>
<div class="author-box">
<p><strong>The Author:</strong> <?php the_author(); ?></p>
<?php if ($author_url) : ?>
<p><strong>Website:</strong> <a href="<?php echo esc_url($author_url); ?>" target="_blank" rel="noopener"><?php echo esc_html($author_url); ?></a></p>
<?php endif; ?>
<?php if ($author_description) : ?>
<p><strong>About:</strong> <?php echo esc_html($author_description); ?></p>
<?php endif; ?>
</div> How This Works
get_the_author_meta('ID')retrieves the numeric user ID of the author for the current post. This is used later if you need to link to their profile.- get_the_author_meta(‘user_url’) and get_the_author_meta(‘description’) fetch the author’s website and bio from their WordPress profile.
- Each section is wrapped in an if statement. This prevents the display of empty fields if an author has not entered a website or bio.
- The function
esc_url()sanitizes the website URL before outputting it to prevent potential security risks. - The function
esc_html()escapes plain text values like the bio or URL text to prevent unwanted HTML injection.
By wrapping everything in conditionals, the section remains clean and professional, showing only the information that exists.
Adding the Edit Author Link
Next, add a link that lets administrators and editors edit the author’s profile directly from the front end of the site. Place this code beneath the author information block:
<?php
$current_user_id = get_current_user_id();
if (current_user_can('edit_users') || $current_user_id === (int) $author_id) {
$author_edit_url = admin_url('user-edit.php?user_id=' . $author_id);
echo '<p><a href="' . esc_url($author_edit_url) . '">Edit Author Profile</a></p>';
}
?> How This Works
get_current_user_id()retrieves the ID of the currently logged-in user.- The condition checks two things:
- Whether the user has the
edit_userscapability (administrators or editors). - Whether the current user’s ID matches the author’s ID.
- Whether the user has the
- If either is true, the Edit Author Profile link appears.
This ensures that your site remains secure while giving your editorial team a convenient way to update author profiles without navigating through multiple menus.
Verifying the Permissions
You can test your setup easily:
- Log in as an administrator or editor and view a post. You’ll see the Edit Author Profile link below the author information.
- Log out or login as a contributor, or visitor. The link will not be visible.
This confirms that the capability check and conditional logic are working as intended.
Why This Approach Is Effective
This method is modern, secure, and efficient. It replaces outdated functions such as get_currentuserinfo() and $user_ID, which are deprecated. It uses conditional checks to keep your layout tidy and leverages WordPress’s role-based permissions system for proper access control.
With this code in place, you’ll have a professional author section that automatically adapts to your users’ permissions, keeping your content management workflow smooth and your templates free from unnecessary code.



