Wordpress文本小工具可以添加任意的html及javascript代码,但是默认是不支持php代码的,如果要使你的Wordpress文本小工具支持php代码,可在当前主题的functions.php文件中加入以下代码:
add\_filter('widget\_text','execute\_php',100);
function execute\_php($html){
if(strpos($html,"<"."?php")!==false){
ob\_start();
eval("?".">".$html);
$html=ob\_get\_contents();
ob\_end\_clean();
}
return $html;
}
添加后即可在文本小工具中添加并正常解析php代码函数。