WordPress 为 pre 标签内的方括号转义

代码如下,只为方括号转义,如果直接使用 htmlentities 函数则会将所有字符转换为 HTML 实体

function pre_content_filter( $content ) {
	return preg_replace_callback('|<pre.*><code.*>(.*)</code></pre|isU', 'convert_pre_entities', $content );
}
function convert_pre_entities( $matches ) {
	return str_replace( $matches[1], FunctionName( $matches[1] ), $matches[0] );
}
function FunctionName($value='')
{
	$value = str_replace("<", "&lt;", $value);
	$value = str_replace(">", "&gt;", $value);
	return $value;
}