Execute PHP in WordPress text widget

[box]CMS: WordPress  Difficulty Level: Easy  Time: 1 min.[/box]

By default, WordPress text widget only allows to execute the HTML code. If somehow you need to run PHP code in the text widget, you would have to add below snippet of code to your theme’s functions.php file – There are no other settings required. After you have put below code in functions.php file of your theme, the PHP code in the text widget would run automatically.

// Run php in text widget
function execute_php($html){
 return $html;


Hello my name is Imran Jafri, I am the Editor and founder of Maboot Mag. I am extremely passionate about Web design, UX and GUI. I love to play with PHP, javascript and Wordpress. Of course I am a MAC and using Ubuntu as my secondary OS. That's all.

Share This Post

Related Articles

© 2019 Maboot.com. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie