Content Marketing

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

  1. 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.
  2. get_the_author_meta(‘user_url’) and get_the_author_meta(‘description’) fetch the author’s website and bio from their WordPress profile.
  3. 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.
  4. The function esc_url() sanitizes the website URL before outputting it to prevent potential security risks.
  5. 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

  1. get_current_user_id() retrieves the ID of the currently logged-in user.
  2. The condition checks two things:
    • Whether the user has the edit_users capability (administrators or editors).
    • Whether the current user’s ID matches the author’s ID.
  3. 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:

  1. Log in as an administrator or editor and view a post. You’ll see the Edit Author Profile link below the author information.
  2. 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.

Douglas Karr

Douglas Karr is a fractional Chief Marketing Officer specializing in SaaS and AI companies, where he helps scale marketing operations, drive demand generation, and implement AI-powered strategies. He is the founder and publisher of Martech Zone, a leading publication in… More »
Back to top button
Close

Adblock Detected

We rely on ads and sponsorships to keep Martech Zone free. Please consider disabling your ad blocker—or support us with an affordable, ad-free annual membership ($10 US):

Sign Up For An Annual Membership