Why doesn’t default WordPress page view use force_balance_tags?

force_balance_tags() is not a really safe function. It doesn’t use an HTML parser but a bunch of potentially expensive regular expressions. You should use it only if you control the length of the excerpt too. Otherwise you could run into memory issues or some obscure bugs.

The other problem is: the function uses two hard-coded lists of elements for single tags and nestable tags. There are multiple places where WordPress uses such lists, and they are not kept in sync. So when you use an element that isn’t part of these lists or changed its nesting behavior you may end up with incorrect markup.

Leave a Comment