函数文档

strip_shortcode_tag()

💡 云策文档标注

概述

strip_shortcode_tag() 是一个 WordPress 函数,用于基于正则表达式匹配从文章内容中移除短代码标签。它处理短代码的转义语法,并返回处理后的内容或 false。

关键要点

  • 函数基于正则表达式匹配来剥离短代码标签。
  • 支持 [[foo]] 语法用于转义短代码标签。
  • 返回类型为 string 或 false,表示处理后的内容或失败。
  • 在 WordPress 3.3.0 版本中引入。

代码示例

function strip_shortcode_tag( $m ) {
    // Allow [[foo]] syntax for escaping a tag.
    if ( '[' === $m[1] && ']' === $m[6] ) {
        return substr( $m[0], 1, -1 );
    }

    return $m[1] . $m[6];
}

📄 原文内容

Strips a shortcode tag based on RegEx matches against post content.

Parameters

$marrayrequired
RegEx matches against post content.

Return

string|false The content stripped of the tag, otherwise false.

Source

function strip_shortcode_tag( $m ) {
	// Allow [[foo]] syntax for escaping a tag.
	if ( '[' === $m[1] && ']' === $m[6] ) {
		return substr( $m[0], 1, -1 );
	}

	return $m[1] . $m[6];
}

Changelog

Version Description
3.3.0 Introduced.