Allow HTML in WordPress Author Bios
templates, wordpressIf you are regular reader of this site than you know I change the theme about as often as I change my socks. This site is more than a marketing and design resource for my readers, it is also a design and usability testing playground for me! And as you may have noticed, the site has undergone a few new layout changes today.
There is one in particular change that I would like to discuss further, adding an author bio to post pages. While this is not in itself a difficult change or anything that would normally warrant a post, I had to make a minor change to the core WordPress code to allow HTML markup in the author bio field.
I wanted to add an author box below my posts that included the author bio from the administration area, but I wanted to use HTML in the bio. When I first tried to add HTML to my bio, I found that HTML markup is stripped when by WordPress by default. This default action by WordPress made it impossible to add links and images or other rich content to the biography field for authors.
To solve this problem, I found a bypass that will allow WordPress to accept HTML markup in the bio.
To do this, you need to open and edit the file: /wp-includes/registration.php
Do a search for the following line of code:
$description = apply_filters(’pre_user_description’, $description);
You need to comment out that line. This is done by adding a // to the start of the line, like this:
//$description = apply_filters(’pre_user_description’, $description);
This will stop WordPress from filtering out your HTML in the author bio field.
Next, you will need to add a caller to your template that pulls the author description. To do this, simply add the following line of code to your template where you wish to display the author bio content:
<?php the_author_description(); ?>
In my case I placed this line within a SPAN that I styled to match the appearance of my site.
You can see it in action below!















February 18, 2009 @ 2:38 pm
Nice! Great addition to the end of a post, especially for people landing on a page inside your site and visiting for the first time, like myself. Saw a tweet about this and had to check it out.
Dan Gorgone’s last blog post… Don’t Design (for the Mobile) Like It’s 1999
Reply
zacheos
Thanks for stopping by… Glad to see a new reader around here!
Reply
May 14, 2009 @ 9:17 pm
[...] forum responder linked to an off-site solution suggesting that a core WordPress file be manipulated. As always, every effort should be made to [...]
May 29, 2009 @ 12:34 pm
Thanks for the post! I was just looking for this solution to embed videos to our authors bios.
Sal B’s last blog post… The Creative Brain Trust
Reply
zacheos
Awesome idea… I had not thought of that!
Reply
June 1, 2009 @ 12:21 am
is there not a way to accomplish this without editing the core files, like through functions.php or something?
Tammy Hart’s last blog post… WordPress: How to Use Categories as Your Navigation Bar
Reply
Adam
There is a way, using functions.php as you guessed. I wrote a short article about using functions.php to allow full HTML in user bios.
Credit goes to Zach for spurring the research that lead to that code.
Adam’s last blog post… Author Exposed Reloaded Plugin – Tonight’s Updates
Reply
June 6, 2009 @ 4:03 am
Thanks for the tip Zach! It really helps me.
Raphael’s last blog post… Une bonne idée pour contourner la loi Evin
Reply
June 25, 2009 @ 6:41 pm
I cannot thank you enough! I lost so much time searching for an answer to this! Thanks a ton!
Reply
June 30, 2009 @ 11:52 am
I’m not sure this is the best way to fix the problem… when you update wordpress to a new version, for example, registration.php will be replaced and the functionality will revert to stripping tags.
A better way is to use the Wordpress Filter API. By default, wordpress uses a function called “wp_filter_kses” to strip potentially harmful content out of user descriptions (i.e., to prevent XSS attacks). You can find this by searching for ‘pre_user_description’ in the file wp-includes/default-filters.php.
You have two options:
1. Completely remove this functionality. This may be dangerous, but only if you let the general public create wordpress accounts, which it doesn’t look like you do. To do this, you can add the following to functions.php:
remove_filter(’pre_user_description’, ‘wp_filter_kses’);
2. Modify the allowed tags to include the ones you want to use. This will also modify rules for HTML tags in comments. There is plenty of info about this in google.
Reply
October 23, 2009 @ 6:19 am
Don’t have time to read the blog daily? ,
Reply
January 18, 2010 @ 3:49 am
I have just done as suggested and now when I try and edit a user I get a white blank screen.
I took a backup of the file before changing and even putting in the backup file is still bringing up a white screen when trying to edit a user.
Anyone else seen this?
Reply