How to Execute php in WordPress Text Widget without a Plugin

Share This Article:

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.

execute php in wordpress text widget without plugin

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.php

Also, it is advised to backup your theme.

  • Login to WordPress dashboard and navigate to Appearance menu.
  • Open, Editor and edit functions.php file in your theme.
  • Simply copy this code and paste it in functions.php and 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.php

Also, 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.php file.
  • 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:

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.

Genesis is the most flexible WordPress theme framework that comes with tons of options. We have been using Genesis on all of our blogs and recommending the same to you. Every bit of it is coded according to the standards. Give it a try!

Speak Your MindComments Policy →

*

Looking for More Awesomeness?

Read previous post:
remove-comment-author-link-wordpress
How to Remove Comment Author Website Link in WordPress

WordPress comment form includes "Website" field, where comment author can add a link to his/her own website. It is a...

Close