WordPress: how to put PHP into a Text Widget

wordpress tweakingThe only thing I love more than WordPress is WordPress tweaking.

Believe or not, there’s no way to get PHP code running within a Text Widget.
I mean, you can have almost all kind of widgets plus HTML-code within them, such as Google Adsense code or whatever banner code.

I needed, though, to include some PHP code in order to render some banner code within a Widget with some sort of logic or randomly but with some notable exception.
Just inserting some simple code into a text widget gets no result at all, so what?

Fire your browser to WordPress extend plugin directory and look for PHP Code Widget.
If you do search for it from within your WordPress itself you might be able (as I did and I recommend it) to be up and running in minutes, otherwise you’ll have to install it into the plugin directory as explained by the author.

Once installed, you can include fully featured PHP code into widgets; I went somehow further by integrating a simple check from the index.php page right where the template itself checks its type: main page, post page, archive or tag page, I included a simple variable (let’s call it $pagetype) and, there we are!
I check for that pagetype variable within the PHP Widget and show banners accordingly: great!

Check image below for an easy explanation:
wordpress php code widget

Check more posts about WordPress.

5KPVRD9K4KAE

This entry was posted in Development, PHP, Programming, Web, Widget, Wordpress and tagged , , , , , . Bookmark the permalink.

One Response to WordPress: how to put PHP into a Text Widget

  1. Pingback: Quora

Leave a Reply