The following column wordpress skills will introduce to you how to run PHP code in WordPress text gadgets. I hope it will be helpful to friends in need!
You can add any HTML code to the WordPress text widget, but the default PHP code added to the text widget cannot run. The following code is very useful!
Add the following code to your current theme’s functions.php file:
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; }
After that, you can add a text widget to the sidebar and enter the PHP function code in it, See if it can run normally.
Previously recommended plug-in: MO Widgets Although PHP can be run in gadgets, the above code is more convenient and practical.
The above is the detailed content of How to run PHP code in WordPress text widget. For more information, please follow other related articles on the PHP Chinese website!