Here’s another tip for all you WordPress users out there. The information below was taken from www.tips4developer.com and the owner retains all copyright to his/her post.
As a WordPress developer you might want to execute PHP code in WordPress Text Widget. At times all of us have this requirement. Unfortunately, WordPress do not allow this. But with the help of below steps you can enable PHP code execution in WordPress Text Widget.
Steps to follow:
1. Add the following code in “functions.php”
add_filter(‘widget_text’, ‘enable_php_code’, 99);
function enable_php_code ($text) {
if (strpos($text, ‘< ' . '?') !== false) {
ob_start();
eval(‘?’ . ‘>’ . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}
2. Go to Appearance > Widgets section and drag a Text Widget to your sidebar.
3. Add your PHP code in Text Widget.
That’s all you are done.