How to add PHP to wordpress text widget

When you need, you can add to the textwidget php script. In standard version, this not work,  but after added simple code in your child theme in file: functions.php, your php code will be executed.

function uniset_php_execute($html){

        ob_start(); eval("?".">".$html);
    return $html;


After that, In your textwidget add simple script, to try it. For example:

echo "Some random number: <pre>".rand()."</pre>";

NOTICE: For security reasons this code is not recommended, you should not use this code on production website, but sometimes it is usable for programmers to display environment variables or for other programming needs: we can check your cache and some other reasons.

Leave a Reply

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