How To Allow PHP In WordPress Widget Area Without Plugin

In WordPress theme, sometime you need to execute custom PHP code in widget to showcase the different information related to your category. Many plugins are available that do this, to add a new type of widget usually called PHP widget. But here you don’t need to install a plugin as it can be done by adding in functions.php file of your theme and these lines will turn by default text widget into a PHP enabled widget.

function execute_php($html){
if(strpos($html,”<“.”?php”)!==false){ ob_start(); eval(“?”.”>”.$html);
return $html;

Source →