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


Top ↑

Return

string Balanced text


Top ↑

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.


Top ↑

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;
	}
}


Top ↑

Changelog

Changelog
Version Description
0.71 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by kitchin

    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()`.

You must log in before being able to contribute a note or feedback.