A Guide to HTML Post Comments in WordPress

WordPress is great for blogs, and of course commenting is an essential part of blogging. Your blog readers can post comments with HTML tags. For their convenience, you can display a list of all allowed HTML tags in the comments form using the following PHP code in functions.php:

Allowed tags: <?php echo allowed_tags(); ?>

Change Allowed HTML Tags

You can also change what HTML tags are allowed in your comments form.

Edit functions.php (located in your wp-content/themes/ directory) and append the following code:


* only allow <strong>, <em>, pre, code, and <a href=""> tags
add_action(‘init’, ‘my_html_tags_code’, 10);
function my_html_tags_code() {
define(‘CUSTOM_TAGS’, true);
global $allowedposttags, $allowedtags;
$allowedposttags = array(
‘strong’ => array(),
’em’ => array(),
‘pre’ => array(),
‘code’ => array(),
‘a’ => array(
‘href’ => array (),
‘title’ => array ())

$allowedtags = array(
‘strong’ => array(),
’em’ => array(),
‘pre’ => array(),
‘code’ => array(),
‘a’ => array(
‘href’ => array (),
‘title’ => array ())

If you enjoyed this post, make sure to subscribe to WPMayor’s RSS feed.

About Jean Galea

Jean Galea is a WordPress developer, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Related Articles

  • A Guide to WordPress Post Formats

    Post formats are one of the most interesting additions to WordPress 3.1. In this post we learn how to use them.

  • Extract All Image Sources from a WordPress Post

    Here's a handy piece of code that extracts all the images from a WordPress post: [php] global $post; if ( preg_match_all('/<img (.+?)>/', $post->post_content, $matches) ) { foreach ($matches[1] as $match)…

  • How to Convert Post Types in WordPress

    Ever wondered if it's possible to convert from one custom post type to another? Yes it is! This can be very useful for example when switching themes. One theme can…

9 Responses

  1. taper roller bearing
    taper roller bearing February 16, 2012 at 03:36 | | Reply

    ok,very goog thank you

  2. html color name
    html color name April 4, 2012 at 19:54 | | Reply

    great tutorrials are shared thanks for this
    html color name

  3. WPAchiever
    WPAchiever February 15, 2013 at 04:15 | | Reply

    I’ll try and see if it works…I hope I won’t mess up my theme’s functions.php CSS code 😛
    Thanks for the tutorial

  4. Santa?
    Santa? May 10, 2013 at 02:04 | | Reply

    This is helpful indeed.

  5. Mike Savag
    Mike Savag June 22, 2014 at 07:43 | | Reply

    Looking for a job as service provider? Post your skills to become a service provider. Hundreds of work categories including: Delivery – Cleaning – Recycling – Shopping – Handyman – Catering – Plumbing – Computer Help – Website Design – Writing – Tutoring – Pet Sitting – Child Care – Gardening

    Are you looking for permanent employment? Search over 1 million job listings. From executive jobs to temporary work

    Labor Bazaar Is A Social Network Driven Labor Marketplace

    Visit: Laborbazaar.com

  6. chetaru
    chetaru July 1, 2014 at 10:06 | | Reply

    nice job…exatly was searching fr the same…

  7. emma
    emma December 1, 2014 at 12:13 | | Reply

    than you for this code. I am finding this one. best coding site

  8. cubedcherry- Michael Steyn
    cubedcherry- Michael Steyn December 24, 2014 at 17:42 | | Reply

    Excellent! This post have just solved my problem. Thank you kindly!

  9. Lex Mark Clavaton
    Lex Mark Clavaton April 27, 2017 at 07:55 | | Reply

    Yes, But if you are looking where to advertise your business online, I have an online to tool to introduce, the iConnect10 – wherein you can build your business, and get paid!!

Leave a Reply