Use PHP in WordPress text widget

Ever wondered how to get php code working in the WordPress text widget? There are some plugins out there wich enable this simple functionality, but why using a plugin if it’s so easy to implement by yourself!

You just have to insert the following code to your functions.php:

// Add PHP functionality to text widget
function execute_php($html){
if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter('widget_text','execute_php',100);

Happy PHP-ing!