PHP in WordPress Text Widget

Allow PHP in WordPress Text Widget. No plugin, functions file solution.

Add the following code to functions.php in child theme folder:

add_filter('widget_text', 'php_text', 99);
function php_text($text) {
 if (strpos($text, '<' . '?') !== false) {
 eval('?' . '>' . $text);
 $text = ob_get_contents();
 return $text;

Source: PHP Text Widget — Allow PHP In WordPress Text Widget – Binary Turf

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *