Saturday 04 February 2012

Allow HTML in WordPress Author Bios

HTMLWhiteBG

If 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!

About the author

Founder of Eos Designs and co-founder of iPrintEasy and a number of other web businesses - an entrepreneur with over 10 years of experience in Internet Marketing - Zach understands what it takes to be successful online and specializes in the development of advertising campaigns and marketing plans for start-ups.
  • http://www.dangorgone.com Dan Gorgone

    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

    • zacheos

      Thanks for stopping by… Glad to see a new reader around here!

  • Pingback: Allow Full HTML in WordPress User Bio Description » BLOG INGENUITY

  • http://www.mayhemandchaos.com/blog Sal B

    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

    • zacheos

      Awesome idea… I had not thought of that!

  • http://www.tammyhartdesigns.com Tammy Hart

    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

  • http://www.kalenga.fr Raphael

    Thanks for the tip Zach! It really helps me. ;-)

    Raphael’s last blog post… Une bonne idée pour contourner la loi Evin

  • http://www.chickflickreviews.net Jake

    I cannot thank you enough! I lost so much time searching for an answer to this! Thanks a ton!

  • Taylor

    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.

    • http://www.josephszenasi.com Joseph

      This helped me. I needed to add target blank and could not find the right way. My blog has only one author, me, so, I used your suggestion. Thanks again.

  • http://link Barbara15

    Don’t have time to read the blog daily? ,

  • PG

    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?

  • murali

    fantastic… i have solved my problem.

  • http://www.ps3-downloads.co.uk Adam

    Thanks, this helped me add a sig box to my forum using the forum server plug in, can I make it so my users can just add an image URL with a [img]URLHERE[/img] sorta thing? also how would I add a image above everyone’s bio’s? hope u can help :)

  • http://www.gizoh.com josh

    Awesome! thanks so much

  • http://www.ruudvandepol.nl Rvdpol

    This works

  • http://djgraphics.co.uk/blog/ Danny

    Haha you genious. This is quick and easy, thanks.

  • http://jackrabbit.com/blog/ Alex @Jackrabbit.com

    This was exactly what I needed. Thanks for the tip!

  • kendrawilson

    Thank you so much I've been looking for this for awhile now!

Powered by WordPress | Privacy Policy | Web Design Miami