How i execute PHP code in WordPress widget without any plugin

If your are a wordpress developer, And you need to execute your custom php code in a wordpress widget,Then i have a simple code snippet for you, which enable you to execute your code in wordpress widget.
So, you don’t have to install any more extra plugin into you wordpress setup.

Add this code in your theme functions.php .Now your theme is ready with this feature without any External plugin.

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

credit:emanueleferonato.com

 

Similar Posts:

    None Found