Text widget is one of the most used widgets in WordPress. It allows users to add ads banner, text, video or any text written in HTML.
For security reason, WordPress disable the execution of PHP code in the text widget. Therefore, if you put any PHP code in the text widget, it simply won’t get executed. Instead, you’ll see text. However, there’s a way to enable the PHP code in the text widget.
Enter PHP Code Widget plugin. This is another plugin by Samuel Wood, or also known as Otto by the WordPress community. If you’ve never heard of him, he’s one of the WordPress core developers.
As the name suggest, this plugin allows you to execute PHP code in the text widget. After activating the plugin, simply drag the PHP Code widget to your widget location. Then simply enter your code in the text widget. Make sure you properly wrap in with the right php tag as shown in the example below.
This widget looks like the text widget, the difference is only on the title of the widget. Here’s the output:
This is not the only way to expand the functionality of the text widget. Before this, we’ve also published a tutorial on how to enable shortcodes in the text widget.
We hope this article helped you to execute the PHP code in the text widget. If you’ve any other suggestion, feel free to drop your comment below.
Leave a Comment