Add Author Box Below Posts

Enhance user engagement by adding an author box with the author’s bio and social media links below each post..

<?php
function add_author_box() {
    if (is_single()) {
        $author_id = get_the_author_meta('ID');
        $author_name = get_the_author_meta('display_name');
        $author_description = get_the_author_meta('description');
        $author_twitter = get_the_author_meta('twitter');
        
        echo '<div class="author-box">';
        echo '<h3>About the Author: ' . esc_html($author_name) . '</h3>';
        echo '<p>' . esc_html($author_description) . '</p>';
        if ($author_twitter) {
            echo '<p>Follow me on Twitter: <a href="https://twitter.com/' . esc_attr($author_twitter) . '" target="_blank">@' . esc_html($author_twitter) . '</a></p>';
        }
        echo '</div>';
    }
}
add_action('the_content', 'add_author_box');

Post Comment