函数文档

unescape_invalid_shortcodes()

💡 云策文档标注

概述

unescape_invalid_shortcodes() 函数用于移除由 do_shortcodes_in_html_tags() 添加的占位符,清理内容中的短代码转义字符。

关键要点

  • 函数接受一个字符串参数 $content,返回移除占位符后的内容。
  • 通过 strtr() 函数将转义字符 '[' 和 ']' 替换回原始字符,避免重新解析 HTML。
  • 该函数自 WordPress 4.2.3 版本引入,主要用于短代码处理流程。

代码示例

function unescape_invalid_shortcodes( $content ) {
    // Clean up entire string, avoids re-parsing HTML.
    $trans = array(
        '[' => '[',
        ']' => ']',
    );

    $content = strtr( $content, $trans );

    return $content;
}

📄 原文内容

Removes placeholders added by do_shortcodes_in_html_tags() .

Parameters

$contentstringrequired
Content to search for placeholders.

Return

string Content with placeholders removed.

Source

function unescape_invalid_shortcodes( $content ) {
	// Clean up entire string, avoids re-parsing HTML.
	$trans = array(
		'[' => '[',
		']' => ']',
	);

	$content = strtr( $content, $trans );

	return $content;
}

Changelog

Version Description
4.2.3 Introduced.