method_utility_format_tags
apply_filters( 'method_utility_format_tags', array $tags )
Filters the bracket shortcodes Method_Utility::format_tags() replaces with markup in headlines and content pulled from post meta and theme options.
Description
Method_Utility‘s format_tags() turns a small set of square-bracket tags into HTML with a straight associative replacement (str_replace_assoc()), so a headline stored as plain text in a meta field or an option can carry a line break or emphasis without allowing HTML. The text is escaped first (esc_html()) and the tags replaced after, which is what makes the tags safe. This filter changes the map: add a tag, change what one produces, or remove one. It runs on every call, which includes format_headline(), get_loaded_headline(), get_headline() and the list helpers.
Parameters
$tags (array) :
Tag ⇒ replacement HTML. Defaults:
| Tag | Replacement |
|---|---|
[br] | <br> |
[mbr] | <br> shown below the md breakpoint only (Bootstrap display classes) |
[dbr] | <br> shown from md up only |
[strong] / [/strong], [b] / [/b] | <strong> / </strong> |
[em] / [/em] | <em> / </em> |
[u] / [/u] | <span class="method-underlined"> / </span> |
[bull] | <span class="method-bull">•</span> |
Source
File: lib/class-method-utility.php, function Method_Utility::format_tags()
return $this->str_replace_assoc( apply_filters( 'method_utility_format_tags', $tags ), $text );
Usage
add_filter( 'method_utility_format_tags', function ( array $tags ) {
$tags['[accent]'] = '<span class="child-accent">';
$tags['[/accent]'] = '</span>';
return $tags;
} );
Notes
- Replacement is literal and in array order, with no nesting rules: a closing tag is just another entry, so pair every opener with its closer.
- Because the source text is escaped before the tags are replaced, the replacement HTML is the only markup that can reach the page — keep it to trusted, static strings.
- The tags apply only to text that goes through
Method_Utility; block content is not affected.
Related
Method_Utility— the classmethod_utility_option_key— the other Method_Utility filter
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Carried over from Method 1.x (introduced in 1.4.2, 95d6aad). |