Add Line Breaks To Author Description In WordPress Themes

by Jhet Bhlak on October 24, 2012

First, let me say I made this much harder on myself than it should have been. There was much kicking, screaming, gnashing of teeth and biting of ass on my part over something pretty simple. I wanted to add line breaks in author bio’s / descriptions in a WordPress blog I run.

What Didn’t Work

  1. I tried just using nl2br(); on the code used to display the author bio in single.php. So instead of the_author_description(); I put nl2br(the_author_description());BZZZTTT Wrong!
  2. Hmm…Next up I researched a little more and found that the_author_description() was deprecated. The replacement code that should be used is: the_author_meta(‘description’);  I thought maybe they took care of the line break issue with the new code. BZZZTTT Wrong!
  3. Fine. Well maybe nl2br(he_author_meta(‘description’)); will work….BZZZTTT Wrong!
  4. All right. I thought I found the solution with this post that used a filter to replace the line breaks with html breaks. It may actually work but it didn’t for me. BZZZTTT Wrong AGAIN!

Epiphany!

Filters! Duhhh! Why not create my own basic filter?!? So I reverted single.php to the old the_author_description(); code, opened up my functions.php file and added the following function / filter at the end:

add_filter('the_author_description', 'lb_to_auth_desc');
function lb_to_auth_desc($content){
return nl2br($content);
}

Boom! All done. Line breaks are now in the author bio’s.

FML I need to brush up on WordPress and php if I’m going to be running into issues like this…:)

{ 2 comments… read them below or add one }

Ian P November 14, 2012 at 5:49 pm

It’s maddening how long this simple little thing took! Try here for a more solid, non-deprecated, solution: http://blog.cosmocatalano.com/wordpress-about-the-author-without-plugins/

Reply

Jhet Bhlak January 10, 2013 at 2:31 pm

The filter and function are now copyable directly into your theme functions file. I noticed today that if you tried to copy and paste them directly off this post, the single quotes would convert to a different single quote than ' and the code would not function.

Reply

Leave a Comment

Previous post:

Next post: