
While it’s a rather horrible idea, this code will permit you to execute PHP code in WordPress widgets. There’s never a need to use it; use shortcodes instead. However, it may come in handy at some point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/* Execute PHP in WordPress Widgets http://www.beliefmedia.com/code/wp-snippets/execute-php-wordpress-widgets */ function beliefmedia_execute_php_widgets($html) { if (strpos($html, '<' . '?php') !==false) { ob_start(); eval('?' . '>' . $html); $html = ob_get_contents(); ob_end_clean(); } return $html; } add_filter('widget_text', 'beliefmedia_execute_php_widgets', 100); |
Again, use shortcodes and enable the widget_text
filter as follows:
1 |
add_filter('widget_text', 'do_shortcode'); |
Shortt URL for this post: http://shor.tt/1XI5