Default text message widget throughout WordPress doesn’t have got the capacity of making PHP rule. If you would like execute php rule throughout WordPress text message widget with no plugin, comply with this particular uncomplicated strategy. Several extensions are available to be able to execute php throughout sidebar widgets, but instead of employing a plugin this particular functionality might be easily attained with the addition of this particular rule.
Now if you want to run a PHP code without editing your theme files as you dont know how to edit and if you do it incorrectly then it can mess up your blog design too so if you have any widget code in PHP then we will recommend you to follow this process for you all upcoming widgets snippets too.
Table of Contents
How To Execute PHP In WordPress Text Widget Without A Plugin?
Step 1:) Copy the below code and Paste in your Theme Function(function.php) file.
/* ------------------------------------------------------------------------- * * Execute PHP In WordPress Text Widget /* ------------------------------------------------------------------------- */ 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);
Step 2:) Update and done.
Customization:
You do not have to change anything. Just after adding this code, go to your Widgets and add a text widget. Now in the text area, just add your PHP snippet code and save that widget. You can also show simple text in that too.
Theme Files Editing Warning:
Keep in mind that every code that you will add in your themes files will be removed when you will change the theme. So after changing your theme, you have to follow this article again and you will get everything back same as it is now.
Last Words:
This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.
Be the first to write a comment.