A Guide to HTML Post Comments in WordPress

Written by Jean Galea
Written by Jean Galea
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...

Partner Sponsors

BionicWP

Full disclosure: If you purchase through a link on our site, we may earn a commission. Learn more.

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:

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

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:

[php]

/*
* 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 ())
);
}
[/php]

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

This article was filed in our archives.
Written by Jean Galea
Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

In this article

Discover More

9 Responses

  1. 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!!

  2. 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

  3. 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

Share Your Thoughts

Your email address will not be published. Required fields are marked *

New discoveries, every week.
Join thousands of designers, developers, and builders that come to WP Mayor to find the best guides, tools, and services for their next website. One email, once a week.
WP Mayor Newsletter

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.

What's missing?