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.

[php] 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;
}
[/php]

Source →

Maan
Author

21 year old designer, blogger and front-end developer. love to share creative design and inspiration.

2 Comments

Write A Comment