Sometimes we need to execute PHP scripts in text widget but by default WordPress doesn’t comes with this feature because of security issues.
You can use few plugins like PHP text widget and PHP Code Widget but why anyone should use those when we can do it within a fraction of seconds.You know what,It takes much lesser time than a installing a plugin.
FInd the functions.php file of your current theme and add the following code at the end of the file.
function php_execute($html){ if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } add_filter('widget_text','php_execute',100);
Now clear the cache if you use Cache Plugins such as WPSuper Cache or W3 Total cache.
To check the working,Paste the following PHP code in a text widget
<?php echo 'Hello World !!!' ?>
Now check the place where you have placed the widget,You should see “Hello World !!!”
If you want to understand the code then visit – Emanuele Feronato – italian geek and PROgrammer
via – WPSquare