RSS feed


How to allow tags in WordPress comments unobtrusively

Scenario: I am using the tinymcecomments plugin to give some formatting capabilities to commenters.
With the latest WP update I realised the span tag was removed from comments; colors attributes are filtered by the kses filter.


After investigating I come across this suggestion in the Codex:

Acceptance of HTML tags in the comments field is managed in the file kses.php, located in the wp-includes folder.

Open this file in a text editor, and locate the list of HTML tags near the top of the file. Each HTML tag is listed on a separate line, in the construction of a PHP array of allowed tags. Lines which begin with // are commented-out, or disabled, so lines which begin with // designate HTML tags that are not allowed in comments.

To stop people from posting HTML in comments, edit your kses.php file as desired to allow or disallow specific HTML tags in comments, by adding // to the very beginning of the appropriate lines of the list. To exclude all HTML tags, comment out all lines which allow HTML tags. Be sure to save your file when done.

That’s a start but hey, is the Codex really suggesting that I alter the WP core? Next update my all precious settings will go away. C’mon, we can do better than that!

In the kses source code I find this:

if (!defined('CUSTOM_TAGS'))
	define('CUSTOM_TAGS', false);
if (!CUSTOM_TAGS) {     

So basically I can redefine all the allowed tags structure in a constant. Not bad. But hey, do I really want to redefine both the $allowedposttags and the $allowedtags variables? Naaah…

So I scavenged in the source code and I came across a fit filter. I wrote a little function for my functions.php file; needless to say, this could have gone into a plugin.

function fa_allow_tags_in_comments($data) {
	global $allowedtags; 
	$allowedtags['span'] = array('style'=>array());
	$allowedtags['p'] = array();   
	return $data;

See? Much more concise than overwriting the variables. And more future-proof: if subsequent versions of WordPress change the variable there is no constant barring the changes.


Be Sociable, Share!

64 responses to “How to allow tags in WordPress comments unobtrusively”

  1. name says:


  2. Lindner says:

    Lastly an outstanding write-up about the topic, continue the great work and therefore I hope to examine a lot more of your stuff in the future.

  3. Dockus says:

    Perfect post! Thanks

  4. Ninjamonkey says:

    this is a test

    [quote]to see if this would be quoted[/quote]

    do not panic, just a test

  5. Allow more tags in WordPress comments form says:

    […] Name () E-mail () Website Comment […]

  6. Stroje do pes 2011 download says:

    Can I simply say what a aid to seek out someone who really knows what theyre speaking about on the internet. You definitely know how to carry a difficulty to gentle and make it important. Extra people have to learn this and perceive this side of the story. I cant believe youre not more in style since you definitely have the gift.

  7. M Wickham says:

    This is exactly what I needed, thanks a lot!

  8. test says:

    Let’s see if some tags work:

    Emphasized text Strong text Computer code text Keyboard text Citation

    strike del quotation marks Italic text Bold text

    Shaming Private Ryan

  9. test says:

    Let’s try again: Emphasized text<br/> Strong text<br/> Computer code text<br/> Keyboard text<br/> Citation<br/>

    This is blockquote so it’s a little longer
    <br/> strike<br/> del<br/> quotation marks<br/> Italic text<br/> Bold text<br/> Shaming Private Ryan

    This ones got Breaks

  10. test says:

    Emphasized text Strong text Computer code text Keyboard text Citation

    This is blockquote so it’s a little longer
    strike del quotation marks Italic text Bold text Shaming Private RyanThis one’s got better breaks (Hopefully)

  11. test says:


  12. Savage says:

    Hi, if you like, MySQL Databases here:

  13. More tags allowed in comments form (Artmov) says:

    […] David Benini: Allow tags unotrusively […]

  14. giełda elektryka says:

    great post, very informative. I wonder why the other experts of this sector do not notice this. You must continue your writing. I am confident, you’ve a great readers’ base already!

  15. Walworth says:

    Hello, Hi, Hey, great article, post, blog, I, we love, like, loved, liked it !!!

  16. test says:
  17. Ascencio says:

    Just in case 2012 is really the end of the world as we know it, it be a good idea to warn future generations of the impending doom by engraving a warning message on a stone tablet. After all, that is what the ancient civilizations, egyptians, mayans did to warn us and ancient aliens?

  18. Egeszseges so says:

    You received a really useful blog page I’ve been right here reading for about an hour. I’m a newbie along with your success is very considerably an inspiration for me.

  19. smart tv streaming says:

    I feel that may be a captivating aspect, it made me assume a bit. Thank you for sparking my pondering cap. From time to time I get such a lot in a rut that I simply feel like a record.

  20. WerGrats says:

    for aaa louis vuitton replica for more

  21. Casad says:

    Wonderful like my site. I love your uzlagom album. I had your billet to my bookmark just bottom my collection of bikers sites and up to Uzlagom favorite site.

  22. Dighton says:

    Holiday İn Turkey – Mysia Travel guide +905336998410 Mehmet Salih AŞAN

  23. Jack says:

    Bold Text

  24. Oren Eckelman says:

    It’s my belief that mesothelioma is definitely the most deadly cancer. It’s got unusual traits. The more I actually look at it the more I am convinced it does not work like a true solid flesh cancer. In case mesothelioma is actually a rogue virus-like infection, therefore there is the possibility of developing a vaccine in addition to offering vaccination to asbestos uncovered people who are really at high risk regarding developing potential asbestos related malignancies. Thanks for revealing your ideas on this important ailment.

  25. Ali Lois says:

    I have been meaning to research and read more on the subject of this specific subject however I basically never had the chance. So thank you very much for writing about this. This is a matter I am considerably involved in. I am just happy I discovered your blog post. You are an great blogger, likely one of the very best I have found. Your web site has actually a great deal of data and I am in fact learning a whole lot from it. Thank you for sharing this information. You’re terrific!

  26. Hafboyday says:

    As we differentiate, our Louis Vuitton store is the same of the biggest experienced website,Receive To Our Louis Vuitton Outlet Assemble for jumble sale take Louis Vuitton Bags, Louis Vuitton Handbags,characteristic guaranteed, free shipping worldwide, shopping with our louis vuitton online. louis vuitton 財布 louis vuitton バッグ ルイヴィトン 買取 louis vuitton バッグ :

  27. read more says:

    Do you might have a spam issue on this site; I also am a blogger, and I was wondering your scenario; we have created some great techniques and we are looking to exchange solutions with other people, be certain to shoot me an e-mail if planning to pursue.

  28. ibhtqfu says:

    The best thing about burberry outlet would be the number of versatility to your line-using a LV purse in each and every design, material, color, as well as a bag for every occasion. Vuitton is certainly the very best known purse brand of our time, then one of the most recognizable brands in the world. Whether you have in mind an existing burberry outlet in brown and beige, a rainbow of beautiful colors using a white Murakami, or perhaps classic, smooth and solid Suhali leather bag, LV would be the brand with every bag imaginable. Its with great pleasure that many of us stock the many highlights from the Louis Vuitton collection, with these array of fine, replica handbags.

  29. Alice Kinston says:

    I was just seeking this info for some time. After six hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that do not rank this kind of informative web sites in top of the list. Normally the top sites are full of garbage.

  30. Mcguckin says:

    healthy life for all

  31. Lore says:

    It seems that if you allow the html tag for code, WP still strips the html code, so you’d need a plugin, right? But then if you uninstall that plugin, you have code saved that can break the rest of your page. You’d think nobody would do that, but hey I just did because I have to disable plugins sometimes to isolate problems, and in that case, disabling causes another problem.

    So, what I mean to ask is, do you think you could expand on this topic, so theme designers can make an informed choice here about what to include? For themes where we won’t be the admin?

    Thanks. :)

  32. qTrodNasienf says:

    Great web site, lots of beneficial facts. fRaiseShanek

  33. xCodeKelson says:

    Spot on with this write-up, I truly assume this web site wants far more consideration. I’ll most likely be once more to read rather more, thanks for that info. kTommyTrodm

  34. zSeanMrxv says:

    Thank you and Please retain updating your Blog. I will probably be stopping by every single time you do . IRisTome

  35. jShaneRoshans says:

    There are actually numerous details like that to take into consideration. That may be a nice point to deliver up. I supply the ideas above as common inspiration but clearly there are questions just like the one you bring up where an important thing can be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am positive that your job is clearly recognized as a fair game. Each girls and boys really feel the influence of only a moment’s pleasure, for the remainder of their lives. rLegaiMorawv

  36. jDoleMrxv says:

    After research a couple of of the weblog posts in your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website record and will probably be checking again soon. Pls take a look at my website as nicely and let me know what you think. wElrodDemodI

  37. cqtuqcnc says:

    We both shared the same group of friends which made it a little odd too. Canada Goose jakke 18897386 71318459 canada goose expedition parka 40054089 cheap michael kors shoulder bags 15497493 Canada Goose

  38. lancel sacs a main says:

    I like this! thanks for share

  39. cs hack download free says:

    Hello! Would you mind if I share your blog with my facebook group? There’s a lot of folks that I think would really enjoy your content. Please let me know. Thank you

  40. bunk beds says:

    Thanks for sharing your info. I reaally appreciate your efforts and I amm waiting for your next write ups thnank you once again.

  41. How to allow tag <pre> in the comments of my site in wordpressCopyQuery CopyQuery | Question & Answer Tool for your Technical Queries,CopyQuery, ejjuit, query, copyquery,, android doubt, ios question, sql query, sqlite query, nodej says:

    […] I add this code on my theme function.php (link of tutorial): […]

  42. Evangelineipk says:

    ジミーチュウ バイカーブーツ

    ジミーチュウ バイカーブーツ

    ジミーチュウ 財布 芸能人

  43. Rogeabige says:

    These stands assistance the products to be eye catching and encourages good company. It operates great for your trade. The value of one’s solution flip outstanding and also the Ceinture Gucci Homme need for it is going to in the long run improve so Bottega Veneta Bags making you a escalating keep. All the assistance that the apparel fixtures give will have an enormous impact for a expanding enterprise.

    Proficiently exhibiting your merchandise Moncler Outlet on these personalized garments shows Bottega Veneta Bags could be the exceptional way to make an impression about the consumers. They are going to be captivated towards your solution and therefore obtain it.

  44. says:

    After looking over a number of the blog posts on your blog, I really like your technique of writing a blog. I saved it to my bookmark website list and will be checking back in the near future. Please visit my web site as well and tell me how you feel.

  45. Deanne says:

    They spring right back into shape and last forever. However, there are many simple tips that you can follow in order to shift your online poker game into overdrive.

    You will not play many hands early on but when you do you should be winning and hopefully increased your stack by a decent amount for the middle rounds, 4 or 5 onwards.

    Here is my web-site :: giochi di pokemon gratis (Deanne)

  46. Cheap BRIXTON Snapbacks says:

    louis vuitton tote

  47. cheap fake oakleys says:

    Wow, this post How to allow tags in WordPress comments unobtrusively | Nutsmuggling is nice, my sister is analyzing these things, therefore I am going to let know her. cheap fake oakleys

  48. louis vuitton koala wallets says:

    louis vuitton koala wallets…

    I didn’t visit school from the age of 13 onwards. For the reason that I had been competing overseas for most with the yr I started carrying out correspondence education….

  49. Lavonda says:

    There’s certainly a great deal to learn about this subject. I like all the points you have made.

    Also visit my web blog :: Oklahoma tornado shelters (Lavonda)

  50. VictorSeax says:

    michael kors handbagsAirconditioned buses are going to be the norm these days. It are to be hell to educate yourself regarding ride all over the a multi functional toaster bus all around the daytime with no aircondition. No window can innovative the an all in one bus load like passengers. They if have examples of these commonsense to educate yourself regarding let passengers camera powershot down on board going to be the bus before they start. It is not gonna money them anything much in the way. michael kors outletNow significantly more and a good deal more it is certainly plausible begin to learn more about advocate healthy eating,ecological food and drug administration So what sample is always that this? Hope experts can really let them know our way of life. michael kors factory outletI am at this moment working everywhere in the an all in one custom design for my very own your small business (as a number of us as a totall re-vamp), and this is this something that I have been wanting to educate yourself regarding do just fine into going to be the many of the new site.Now I are aware of that in that case Thanks that is why much in the way! michael kors outletThank your family as well as for sharing these much like your life experiences about your best family member I am apologise and then for my very own question that was hurting your family I am in reality hopping all your family if that is so Please take care yourself. michael kors factory outlet

  51. madearcaria says:

    moUupS7tZ3 GQUodsS9U4 &nbsp&nbsp<a href= > moUupS7tZ3 GQUodsS9U4 </a> のみによる最低支払を作るとき、あなたはその後負っ残高に対する利息をお支払いいただきます。これはまたあなたのクレジットカードの債務残高が増加します。あなたが唯一の原因で毎月最低支払額を作っている場合は、新しい毎月の利息は、前ヶ月バランスに計算されます。

    mcm 財布 mcm バッグ 新作 クロエ 長財布 新作 シャネル チェーンウォレット mcm アウトレット mcm バッグ トート 時計 ブランド

    クロムハーツ 財布 激安 グッチ 長財布 エムシーエム キーケース


    chanel 時計 トリーバーチ バッグ 激安 marc by marc jacobs バッグ ミュウミュウ リボン 財布 ルイヴィトン バッグ 女性 miumiu アウトレット moncler モンクレール エルメス 激安

    ミュウミュウ リボン 財布 ミュウミュウ メンズ 財布

    tb moncler jp out

  52. Obat Alami Asam Urat says:

    kapayunan eung nu ieu mah :-)

  53. Obat Serangan Jantung says:

    I agree :-)

  54. Obat Leher Bengkak says:

    it was Amazing Obat Radang Otak Pada Anak

  55. Obat Angin Duduk says:

    April Wish ? Obat Kanker Kandung Kemih

  56. Obat Penyempitan Pembuluh Darah says:

    thank you for this very useful information. I am very interested in posting your articles. every article that you write very educational and beneficial for the wider community.

  57. Customized Youth San Diego Chargers Blue new jerseys sale says:

    Authentic nfl jerseys Ravens throwback jerseys sale

  58. Vacheron Constantin Watches Online says:

    The added comfort which comes with employing a touch screen watch isn’t only limited to devoid of to press physical buttons to get things done on it. In addition, this is also an effective methods to remind each other from the love they share even when they are physically apart. Most people think Italian watches are just for men, as watches are one of the few products acceptable among men. There a wide range of watches designed particularly for girls through the very young to adolescence. He is incredibly well acknowledged for his reliable, chic and historical designs that attract the buyers as well as satisfies the flavour of any category he explains.

  59. rea says:

    Have youu ever thought about publishing an e-book or guest authoring on other websites?

    I have a blog based upon on the same information you discuss and would really like to have you share some stories/information. I know my subscribers would appreciate your work. If you are even remotely interested, feel frese to shoot me an email.

    Also visit my webpage: rea

  60. ruletka97 says:

    азартные игры смс [url=]казино онлайн на рубли гривны[/url] онлайн казино играть бесплатно шарики, [url=]казино пополнить webmoney[/url]

  61. lose weight fast pills over the counter says:

    I like it when people get together and share ideas. Great site, stick with it!

  62. quadri famosi says:

    These stands assistance the products to be eye catching and encourages good company. It operates great for your trade.

    stampe su tela This is a link to a website on the World Wide Web.

    dipinti quadri famosi

  63. nike free run 3 heel to toe drop says:

    mbt shoes stores las vegas nike free run zebra karen millen official outlet lululemon black and white hoodie discount mbt shoes fitflop original walkstar where to buy mbt shoes in australia mbt garissa women white blue shoes tiffany and co sets nike free run 3 womens sale karen millen fashion designer tiffany s rings tiffany & co in new york tiffany co dubai walking in vibram five fingers mbt M.Walk Peachblow Shoes nike free 5.0 v4 leopard mbt chapa men shoes pumpkin black nike free run 2 shoes for sale nike free run mens white

  64. ケイトスペード gold coast says:

    ケイトスペード gold coast…


Leave a Reply

You must be logged in to post a comment.