让WordPress文本小工具支持简码(shortcodes)和PHP代码

WordPress文本小工具默认是不支持支持简码(shortcodes)和PHP代码的,要让它支持,只需将下面的代码添加到当前主题的 functions.php 文件即可:

//让文本小工具支持简码

add_filter('widget_text', 'do_shortcode');

//让文本小工具支持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;

}


版权声明:本文来源于互联网,如有侵权,请联系下方邮箱,一个工作日删除!