Allow PHP in WordPress text widgets Trick & Tips

| December 22, 2012

There are many plugin that can execute php code in wordpress widget but If you want to execute php code in your wordpress widget without any plugin help simply follow these instruction.

  • Open your WordPress Dashboard like http://yourdomain.com/wp-admin
  • Then click on Apperance & Click on Editor
  • Then click on functions.php fine on the right hand side & copy and paste in it.
  • Go to WordPress Appearance Widget Section, add some php code or script to text widget and check it.

 

function php_text($text) {
 if (strpos($text, '<' . '?') !== false) {
 ob_start();
 eval('?' . '>' . $text);
 $text = ob_get_contents();
 ob_end_clean();
 }
 return $text;
}
add_filter('widget_text', 'php_text', 99);

 

wordpress-appearance-editor

wordpress-function-editor

function-editor

Tags: , ,

Category: Wordpress

Leave Your Comments