Skip to content

Instantly share code, notes, and snippets.

@eccentricpixel
Created July 21, 2014 01:30
Show Gist options
  • Save eccentricpixel/2671c2876086af55439a to your computer and use it in GitHub Desktop.
Save eccentricpixel/2671c2876086af55439a to your computer and use it in GitHub Desktop.
PHP and shortcodes in widgets. Put in theme's function file.
// Enable PHP in widgets
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;
}
// Enable shortcodes in widgets
add_filter('widget_text', 'do_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment