Skip to content

Instantly share code, notes, and snippets.

@zenman
Created February 19, 2014 18:23
Show Gist options
  • Save zenman/9098209 to your computer and use it in GitHub Desktop.
Save zenman/9098209 to your computer and use it in GitHub Desktop.
PHP in Text Widgets Function
//To use PHP code in a text widget (useful for links and conditionals), place this code in your theme's functions.php file.
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment