PHP Tricks

Execute PHP Code in Text Widgets

Execute PHP Code in Text Widgets

Execute PHP code in text widgets. By the default, text Widget in WordPress allows only writing text. And There is some plugins directory in the official WordPress widgets that allows you to add PHP inside a widget. Alternatively, you can use that snippet of code to allow PHP code to be executed.

File to edit: functions.php


[box type=”shadow” align=”aligncenter” class=”” width=””]

function php_text($text)

{ if (strpos($text, ‘<‘ . ‘?’) !== false)

{ ob_start(); eval(‘?’ . ‘>’ . $text); $text = ob_get_contents(); ob_end_clean(); } return $text; } add_filter(‘widget_text’, ‘php_text’, 99);



By this code you can Execute PHP code in text widgets.


About the author

Hamid Awan

Hamid Awan is a computer Geek, Internet Entrepreneur, Business Guy, Blogger and Digital Marketing Specialist. He also helps companies to grow their Online Business. At Tech Entires he writes about Money Making Ideas, Business, Android Apps, Blogging, WordPress, SEO, Technology and Computer Tips and Tricks. If you have any suggestion, you can contact us through our Contact Us Page

Leave a Comment