WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/balanceTags

Description

Will balance the tags if forced to or the option is set to balance tags.

The option 'use_balanceTags' is used for whether the tags will be balanced. Either the $force parameter or 'use_balanceTags' option need to be true before the tags will be balanced.

Usage

<?php balanceTags$text$force ); ?>

Parameters

$text
(string) (required) Text to be balanced
Default: None
$force
(boolean) (optional) Forces balancing, ignoring the value of the option.
Default: false

Return Values

(string) 
Balanced text

Examples

Unclosed LI tags

<?php
$html = '<ul>
  <li>this
  <li>is
  <li>a
  <li>list
</ul>';
echo balanceTags($html, true);
?>

Will output this HTML:

<ul>
  <li>this
  </li><li>is
  </li><li>a
  </li><li>list
</li></ul>

Notes

Change Log

Since: 0.71

Source File

balanceTags() is located in wp-includes/formatting.php.

Related

See also index of Function Reference and index of Template Tags.