Execute PHP In WordPress Without Using Any Plugin

Some people would want to execute PHP codes in WordPress’ default text widget but this is not possible since it does not support such a task. There are, however, a number of plugins available that you can use to do this.

But thanks to Marvie Pons of TriptripperTips who shared this helpful snippet of code, you won’t have to install and use any plugins anymore. Just copy/paste and add the code below into your functions.php file.

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

What the code does is turn the default Text widget into a PHP-enabled widget. Once you’ve edited and saved your functions.php file, you’re done!

 

Incoming search terms for the article:

Related Posts

eBag Toolkit

Creating a Psychedelic Art Effect in Your Portraits

EWWW Image Optimizer

Inspirational Photo Retouches By Cristian Girotto

1 Comment

  1. Salma

    08.23.2012

    How do you add php code in pages without using plugins?