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

注:虽然可以实现在小工具运行php代码,但是这个可能存在一定的风险,而且也不支持复杂的函数,所以不推荐大家使用。

来源:

https://www.wpdaxue.com/widget_text-support-shortcodes-php-code.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32751.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?