balanceTags( string $text, bool $force = false ): string
Balances tags if forced to, or if the ‘use_balanceTags’ option is set to true.
Parameters
-
$text
string Required -
Text to be balanced
-
$force
bool Optional -
If true, forces balancing, ignoring the value of the option.
Default:
false
Return
string Balanced text
More Information
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.
Source
File: wp-includes/formatting.php
.
View all references
function balanceTags( $text, $force = false ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( $force || (int) get_option( 'use_balanceTags' ) === 1 ) {
return force_balance_tags( $text );
} else {
return $text;
}
}
Changelog
Version | Description |
---|---|
0.71 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Unclosed LI tags
Will output this HTML:
The `use_balanceTags` option has default 0. The admin UI for it was removed several years ago, along with the UI for `use_smilies` (default 1), in Dashboard/Settings/Writing. So the core filters calling `balanceTags()`, such as ‘content_save_pre’, do nothing unless the user set an option in the distant past, or a plugin/theme changed the setting.
The bug ticket back then said the TinyMCE editor handles the balancing in ‘Visual’ mode, and users in ‘Text’ mode should be allowed to do their own balancing, by default. Opinion changed to that as the ticket developed: https://core.trac.wordpress.org/ticket/5161
Most coders will want to use `force_balance_tags()` instead of `balanceTags()`.