Mar 102014
 
php

Rather than adding the bloat of one of the php plug-ins to your WordPress site you can just add a small piece of code to your functions.php.

 /** Execute PHP code in a standard text widget **/
 add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

You should really create a child theme and put this code in there rather than in your theme’s functions.php as if you upgrade your theme you will lose the custom code.

 Posted by at 2:43 pm