Why doesn’t default WordPress page view use force_balance_tags?

I noticed that the default WP theme uses force_balance_tags for listing posts’ excerpts. This way, it doesn’t cause major html breakage whenever someone writes a post like

<div><b>This is an excerpt. <!--more--> and this is more text... </b></div>

It will close tags instead of bolding everything, and breaking div.

Read More

Why doesn’t the normal wordpress page do this by default, in the default theme? That way, broken page content like:

</div></div> now text is not where it's supposed to be </div> unmatched tags

would not cause unexpected behavior.

Was this an oversight, or are there certain things that break when using force_balance_tags on pages?

Related posts

Leave a Reply

1 comment

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