get_tag_regex() WordPress Function

The get_tag_regex() WordPress function is used to retrieve the regular expression used to match tags in content. This function is useful for modifying how tags are matched and displayed in your content.

get_tag_regex( string $tag ) #

Return RegEx body to liberally match an opening HTML tag.


Description

Matches an opening HTML tag that:

  1. Is self-closing or
  2. Has no body but has a closing tag of the same name or
  3. Contains a body and a closing tag of the same name

Note: this RegEx does not balance inner tags and does not attempt to produce valid HTML


Top ↑

Parameters

$tag

(string)(Required)An HTML tag name. Example: 'video'.


Top ↑

Return

(string) Tag RegEx.


Top ↑

Source

File: wp-includes/functions.php

function get_tag_regex( $tag ) {
	if ( empty( $tag ) ) {
		return '';
	}
	return sprintf( '<%1$s[^<]*(?:>[\s\S]*<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
}


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Introduced.

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
Show More