wp_remove_surrounding_empty_script_tags


wp_remove_surrounding_empty_script_tags ( $contents )

Access:
  • private
Parameters:
  • (string) contents Script body with manually created SCRIPT tag literals.
See:
Returns:
  • (string) Script body without surrounding script tag literals, or original contents if both exact literals aren't present.
Defined at:

Description

Removes leading and trailing _empty_ script tags.This is a helper meant to be used for literal script tag construction within `wp_get_inline_script_tag()` or `wp_print_inline_script_tag()`. It removes the literal values of "" from around an inline script after trimming whitespace. Typically this is used in conjunction with output buffering, where `ob_get_clean()` is passed as the `$contents` argument. Example: // Strips exact literal empty SCRIPT tags. $js = '; 'sayHello();' === wp_remove_surrounding_empty_script_tags( $js ); // Otherwise if anything is different it warns in the JS console. $js = ''; 'console.error( ... )' === wp_remove_surrounding_empty_script_tags( $js );

Related Functions

wp_print_script_tag, wp_get_script_tag, wp_get_inline_script_tag, __return_empty_string, remove_rewrite_tag

Top Google Results

User discussions

wpseek mobile