Saturday 18 January 2014

Allow Users To Add PHP code in Text Widget

Wordpress text widget is an awesome widget where you can add text , html or javascripts any where but we cannot add php code in it. In order to execute php in text widget use following snippet. Now add the following snippet in functions.php file.



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

No comments:

Post a Comment