WordPress 文本小工具中可以添加任意 HTML 代码,但默认 PHP 代码添加到文本小工具中却不能运行,下面的这段代码很有用!
将以下代码添加到您当前主题的 functions.php 文件:
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}

之后,可以将一个文本小工具添加到侧边栏中,并在其中输入 PHP 函数代码,看看是不是可以正常运行了。