PHP Code Widget
Plugin: PHP Code Widget
Version: 2.1
Last updated: 604 days ago.
Downloaded: 152,818 times.
Overview
The normal Text widget allows you to insert arbitrary Text and/or HTML code. This allows that too, but also parses any inserted PHP code and executes it. This makes it easier to migrate to a widget-based theme.
Download Now
Requirements
WordPress 2.8 or higher.
Features
- Like a Text widget, but works with PHP code.
- PHP Code must be in tags to function.
Installation Instructions
- Upload the files to the `/wp-content/plugins/php-code-widget/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
Licensing
This plugin is licensed under the GPL Version 2 only.
Method to get support
You are free to email me, however I am also a moderator at the WordPress.org support forums, so you’ll find me there as well.

I was looking for something like this. I was so noob when I try to put php int text/html widget box and that doesnt works. Thanks for this.
I am a WP newbie, so I just followed the instructions and uploaded the execphp.php file and activated it thru the Plugins screen. So far, so good.
When I make a new post thru
1. VISUAL mode, is just printed on the screen (as text)
2. HTML mode, it becomes
Neither way is getting parsed, what am I doing wrong?
Thanks
This plugin doesn’t execute code in posts. It creates a sidebar widget which will run PHP code.
Oh okay, thanks for the quick reply, Otto!
Thank you for yr plugin. I had it installed fine on one site. I cloned that site, but on the cloned site none of the widgets are copied over. I copied ALL the files and SQLed the whole database. The ONLY file I changed was wp-config.php, pointing to the new database. Everything else works fine. I don’t know if the “problem” is with your widget, or with wordpress cloning widgets. I took special care with wp-options, ID=195. Since EVERYTHING is cloned except pointing to the new database, I’m at a loss to understand why 1 installation would show the widgets, and the other not.
The new installation had all the plugins correctly installed, also.
anyway thank you again, for yr nice widget, as wp itself is very php, it’s kind of strange that it is not built in into the source code.
Moving blogs around is finicky in WordPress in general. If the URL is different between the two sites, search through for where that URL might be in the database. Some of the rows of the options table incorporate it in as a hash or plaintext in the key names.
Will this plug-in let me add html to a widget _title_?
Thanks.
No, it won’t. It only processes code in the body of the widget. Titles get stripped of tags in the core code.
Bummer. Thanks for responding at least.
I am completely new to WP and might I say, completely lost too. After 3 years of blogger, this is a very new playing ground. My feeds are wrong, my stats are wrong, and I need to fix a few things.
Was trying to customise my feedburner feed to include images and make it pretty, but I cannot find a custom feed php in the theme I have installed. It’s the pixel happy child theme. Should I be looking somewhere else. Code is scary for me, but I would love some direction. Many thanks for reading this…
Cheers,
Deeba
vindee@airtelmail.in
Themes don’t control the feed.
Look for plugins to add on the changes and features you want, instead of trying to code them yourself: http://wordpress.org/extend/plugins/
I have used your plugin for quite some time maybe more than a year. I am happy with it, thanks, i use it to get weather data from my weather station that publish data in xml. Since aprox 2 days ago my site (http://climaya.com) became unresponsive, it was slow and was not able to deliver the data, I found out after disabling your plugin it became responsive again, wp-admin site and other sites in server loaded ok.
What could be the problem or where to check, ? I implemented same in other wp site, for the same purpose and there is working fine.
Norman
You’d have to look in your own code. The PHP Code widget is basically identical to the normal text widget, with an eval that makes it run the PHP code. There’s nothing special about it. Any errors you encounter with it happen from your own code in it, not from the widget itself.
Otto, I’m from Brazil, there are days I have been looking for a way of NET to decode a
code, so I thought, you are one of the fastest decode … I know here where
I’m posting has nothing to do with it, but if you can help me
decode it, stay grateful. http://pastebin.com/j9L9zrxQ and forward to email
flaviounai@gmail.com
Use the decoders: http://wordpress.org/support/topic/how-to-decrypt-an-encoded-theme
Getting this after recent WP upgrades
Fatal error: Call to undefined method WP_Error::get_item_quantity() in /public_html/2011/wp-content/plugins/php-code-widget/execphp.php(44) : eval()'d code on line 8Could you please you fix the widget plugin code? That will be worth a beer definitely
There’s nothing wrong with the widget. The error lies in whatever code you put in the widget. That’s what the “eval()’d code” bit means.
Hi Otto, I love this widget; I’ve been using it for 6 months on my website above to fetch my Twitter feed with no problems.
Now after the most recent WP upgrade, I am also getting a similar error to @ommunist above is getting. (Warning: file_get_contents(http://search.twitter.com/search.atom?q=from:ChicSteals&rpp=1) [function.file-get-contents]: failed to open stream: Connection timed out in /public_html/wp-content/plugins/php-code-widget/execphp.php(44) : eval()’d code on line 26
Are you sure there’s no issue with the widget?
I haven’t changed anything in the widget’s code at all or installed any new plugins that could account for this error, but now it’s not fetching my Twitter feed as it used to after the WP upgrade to 3.2.1. (Which is the only thing that I could think of to account for this behavior)
Thank you for all your work on this!
Yes, nothing is wrong with the widget. Your own error says so.
Whenever you see “eval()’d code”, that’s telling you that the error is in the code you have put into the widget. Your code is what is being “eval()’d” here.
So the error is in your own code, not in the widget itself.
Your specific error is occurring because your site can’t get a response back from Twitter. Nothing to do with the widget or with WordPress.
Carly, if your PHP code stopped getting a response from Twitter at the end of August, then was due to Twitter’s shutdown of the API-type that your code used (details, http://mashable.com/2010/06/17/oauthcalypse-delayed/)
Since Code-Widget just runs the PHP you feed it, you’ll have to update your PHP to match. An easier method might be to find a Twitter widget in the WP plugin directory that was updated.
Thank you so much Mike! After posting on here, I spent about 4 hours of Googling the issue and I finally figured out that Twitter had shut that API-type down and that’s why the PHP code widget wasn’t fetching the feed.
Unfortunately I couldn’t find any other PHP code that would work with Twitter, so finally had to abandon the PHP code widget. I installed a standard Twitter widget through WordPress, but am still lamenting my old one as I was displaying the Twitter feed inside a speech bubble coming from my Twitter avatar, which I really liked.:-(
Thanks for your info!
After moving my site to another server, your fantastic plugin stopped executing the php-code. All other text workd fine. Not the php. Even a simple code like
I’ve tried other php-executable-widgets, but it’s the same result – so it’s not your plugin it’s server related.
Do you have any experience about this and perhaps a solution?
/Raffe Bergwall
The plugin uses eval() to run the code. Some PHP setups have eval() disabled.
How can we use this to display Contact Form 7 in widget. I mean the Shortcode doesnt work by default in “Text Widget”
Hello Otto,
Thank you for wonderful plugin !
I noticed that the php code widgets disappear when I move my website to another server. They’re not visible anymore in the widgets section of WordPress.
I still can add new php widget but the old ones are deleted.
Have you a suggestion ?
Thank you for your help.
Best regards.
Widgets of any sort don’t migrate between servers. They’re not part of the export/import process.
Thank you for your quick reply Otto !
All other widgets are present except php code widgets…
Widgets of any kind are not included in a WordPress export/import operation. The PHP Code widget is not special in this respect. NO widgets will be preserved in moving a site from one server to another. It simply doesn’t work that way.
If you migrate the database as a whole, then yes, widgets will be preserved in such a transfer. However, if you don’t activate the plugin on the new site before doing that, then any widgets made by plugins will get removed on the first load of the page, because the code for them isn’t active on the new site yet.
The PHP Code widget is almost exactly identical to the built in Text widget, with only one minor change to allow PHP Code to work.
O i think i didn’t explain very well.
I didn’t export, i made a copy of my site in order to install it to another server…
“Made a copy of the site” is so vague as to be useless. What do you mean by “made a copy”, exactly?
If you copied the database, then widgets would indeed get transferred, but widgets created by plugins would be removed on the first load of the new site because the plugins on the new site were not activated yet. If the plugin is inactive then the widget is missing and so WP will remove the widget from the sidebar when it sees that.
I made a copy of the DB and of the files.
All the plugins are active. All the widgets appear on the transfered site except the PHP code widget.
I needn’t to active php code widget because its code is written in functions.php.
Could it be the problem ?
thank you for your help Otto !
Well, if you’re not using the plugin and have put code in functions.php instead, then I have no idea what you’re doing or why you’re having trouble.
Regardless of this, this is not a problem with the plugin. It is not a bug. It will not be “fixed”.
Ok, thank you anyway
thanks for your plugin
I’m trying to use toggles in the php widget but the tricky part is that they are loaded from a php file called as an includes.
in the functions.php I added
add_filter(‘widget_text’, ‘do_shortcode’);
add_filter(‘widget_execphp’, ‘do_shortcode’);
Loading the php file works. Manually entering the toggle in the widget works (text widget and php widget). but the toggle doesn’t work if it is included in a file. any idea why, and how to resolve that? I know it isn’t really a ‘problem’ with your plugin but I thought you might know. regards,
Do blogspot have same gadget like this plugin where I can paste my php code.
[...] none Options All -Indexes -LiensLe site de l’auteur du compteur NotoonLe site d’Otto PHP Code WidgetPage de téléchargement-Je vous recommande aussi la lecture des sujets suivants :Extension Contact [...]
Do you know a similar script that allows placing the original php code in posts or pages. Just like yours.
Ty