No Plugin – Execute PHP Code In WordPress Widget

Sometimes in your WordPress theme you need to execute custom php code in a widget, because you want to display different information according to the category you are in, or simply because you need to execute a php script into that widget. Sometimes we need to execute PHP scripts in text widget but by default WordPress doesn’t comes with this feature because of security issues.

Find the functions.php file of your current theme and add the following code at the end of the file.

Now clear the cache if you use Cache Plugins such as WPSuper Cache or W3 Total cache.

To check the working, Paste the following PHP code (Example) in a text widget

and check out the output in widget. Yeah now you can play with you PHP scripts but do it your security level. Thanks for sharing with your friends.

Leave a Reply

Your email address will not be published. Required fields are marked *