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.

[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 →

0 Likes
Maan
Maan

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

There are 2 comments
  1. Michael DeMutis

    Doesn’t work

    • Maan

      It’s still Work..

Your email address will not be published. Required fields are marked *

div#stuning-header .dfd-stuning-header-bg-container {background-image: url(http://www.downgraf.com/wp-content/uploads/2017/04/login-back.jpg);background-size: cover;background-position: center center;background-attachment: scroll;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 500px;}