Friday, February 24, 2017

How to Use PHP Code in WordPress Widget Without Plugin

How to Use PHP Code in WordPress Widget Without Plugin


Sometimes we need to put the PHP code into a WordPress widget but didnt work the code. Because WordPress does not allow to put the PHP code in the widget, but you can fix this issue with simple codes. If you want to use PHP code via a plugin, then a lot of plugins are available to provide this facility. But if you want to use PHP code without any plugin, then follow below steps.


Find your WordPress functions.php file and paste below lines:

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;
}

Save your functions.php file and put your PHP code into WordPress widget. It will work Fine.

Incoming Search Terms: 

execute php in widget, PHP in widget, use PHP in wordpress widget,PHP code for widget, execute php without plugin


Available link for download