balanceTags() WordPress Function

The balanceTags() function is used in WordPress to ensure that all HTML tags are properly balanced. This function can be used to correct errors in the HTML code of a WordPress post or page.

balanceTags( string $text, bool $force = false ) #

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 value: 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

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
VersionDescription
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More