WordPress.org

Ready to get started?Download WordPress

Forums

Including author bios in the_content (7 posts)

  1. kgagne
    Member
    Posted 4 years ago #

    I would like my bloggers on challengeblog.org to have their bio appear at the end of each blog post. I have modified index.php to include this line right after the_content is displayed:

    <?php echo the_author_meta('description'); ?>

    However, other plugins, such as Simple:Press Forum and Tweet This, are putting their widgets first, separating the author's post from the author's bio. Also, since the author's bio is not actually part of the_content, it does not go out in the site's RSS feed.

    Is there a way to include the author's bio as part of the content, giving it precedent over other plugins and including it in the RSS feed?

    Apologies if I've placed this question in the wrong forum.

    -Ken

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    How about:

    FUNCTIONS.PHP:

    if( ! function_exists( 'author_bios') :
    	function author_bios() {
    		$author_bio = '<div class="author-bio"><span class="author-name">' . get_the_author_meta( 'display_name' ) . '</span>: ';
    		$author_bio .= '<span class="author-description">' . get_the_author_meta( 'description' ) . '</span>';
    		$author_bio .= '</div>';
    		return $author_bio;
    	}
    add_filter( 'the_content', 'author_bios' )
    endif;
  3. kgagne
    Member
    Posted 4 years ago #

    Thanks, Esmi! I'm not well-versed in PHP, so my apologies if I report back with anything that should be obvious.

    I added the above code to functions.php and got an unexpected ':' error on the first line. I tried adding an extra close parenthesis before the colon and got an unexpected T_ENDIF error on the last line. I tried deleting the first and last line entirely and got no error — but each post's content was replaced entirely by the author's bio.

    Any idea what I'm doing wrong that's causing this code not to work?

  4. chinmoy
    Member
    Posted 4 years ago #

    if( ! function_exists( 'author_bios' ) ) :
    	function author_bios() {
    		$author_bio = '<div class="author-bio"><span class="author-name">' . get_the_author_meta( 'display_name' ) . '</span>: ';
    		$author_bio .= '<span class="author-description">' . get_the_author_meta( 'description' ) . '</span>';
    		$author_bio .= '</div>';
    		return $author_bio;
    	}
    add_filter( 'the_content', 'author_bios' );
    endif;

    try it again now

  5. kgagne
    Member
    Posted 4 years ago #

    Thanks, Chimnoy! The missing semicolon should've been obvious. I really need to better acquaint myself with PHP syntax...

    This updated code reports no error, but as I encountered in my own efforts to correct the first version, the result is a complete replacement of the post's content with the author's bio.

    I found something similar that puts the author bio at the bottom:

    http://www.sitesketch101.com/article-footer-author-info#comment-18415

    and modified it thusly:

    function get_author_bio($content='') {
    	global $post;
    	if (!is_page()) {
    		$post_author_description=get_the_author_meta("description");
    		$html="\n";
    		$html.="<em>";
    		$html.= $post_author_description."";
    		$html.="</em>";
    		$content .= $html;
    	}
    	return $content;
    }
    add_filter('the_content', 'get_author_bio');

    ... but I don't think it's addressing my original concerns of taking precedent over other plugins, or being included in the RSS.

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    Sorry about the syntax error. It was a completely "off the top of my head" piece of code.

  7. kgagne
    Member
    Posted 4 years ago #

    Ah! I spoke too soon about the bio being included in the RSS. I guess FeedBurner didn't refresh as quickly as I thought I did.

    The bio still comes after other plugins' widgets, but I can live with that.

    Thanks,

    -Ken

Topic Closed

This topic has been closed to new replies.

About this Topic