Default text widget in WordPress doesn’t posses the capability of executing PHP code. If you want to execute php code in WordPress text widget without any plugin, follow this simple trick. Many plugins are available to execute php in sidebar widgets, but instead of using a plugin this functionality can be easily achieved by adding this code.

Check Out : How to Remove Comment Author Website Link in WordPress
Execute php in WordPress text widget without a Plugin
You need to edit this file in theme folder…
functions.phpAlso, it is advised to backup your theme.
- Login to WordPress dashboard and navigate to Appearance menu.
- Open,
Editorand editfunctions.phpfile in your theme. - Simply copy this code and paste it in
functions.phpand update file. - You have successfully added code and its time to test drive it.
- Go to Widget Section, add some php code to text widget and check it.
function php_execute($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter('widget_text','php_execute',100);
Also Read : How to Disable or Limit Post Revisions in WordPress
Execute php in WordPress text widget for Thesis Theme
You need to edit this file in theme folder…
custom_functions.phpAlso, it is advised to backup your theme.
If you are using Thesis theme, then follow these steps
- Login to WordPress dashboard and navigate to Thesis Options.
- Go to Custom file Editor and open
custom_functions.phpfile. - Add the below code to it and save the file.
- Voila, you are done with editing part, go to widgets section and check the text widget using some php code.
function php_execute_thesis($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter('widget_text','php_execute_thesis',100);
Functionality of this Code:
- More information on this code snippet is available at Emanuele Feronato.
If you got any query related to this article, please do post a comment, we will get back to you soon. Meanwhile subscribe to our feeds.


How to add nofollow to all External Links in your Blog
How to Effectively Interlink Blog Posts in WordPress
How to Disable or Limit Post Revisions in WordPress
How to Change Background Color of Posts in WordPress Admin
How to Display Facebook, Twitter and RSS Counts in Plain Text
How to Remove Date from Meta Description in Search Results