WordPress文本小工具怎样支持php代码

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;
}

文章源自堕落的鱼-https://www.duoluodeyu.com/1890.html

添加后即可在文本小工具中添加并正常解析php代码函数。文章源自堕落的鱼-https://www.duoluodeyu.com/1890.html 文章源自堕落的鱼-https://www.duoluodeyu.com/1890.html

 
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证