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:

[code]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

Leave a Comment

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

Scroll to Top