WordPress Weather Widget

Number 5 in Widget-A-Day is a Weather widget.

It isn’t too fanciful. It displays the current condition, temperature, and the feels like temperature. It uses weather.com‘s xoap api to retrieve the information. I’ll probably come back to this and make it better.

Download weather.zip

SVN Checkout
svn co http://svn.wp-plugins.org/weather-widget/trunk

Default display:

Admin panel:



  1. Download weather.zip
  2. Extract and upload weather.php to the plugins/ directory
  3. Enable Weather Widget in the Plugin admin panel
  4. In widget admin panel, place Weather in the sidebar, and edit it to enter your location


The location can either be a zip code for US users or the locid. To find the locid, you can do a search using http://xoap.weather.com/search/search?where=[search parameters].This will return an XML file with search results and their corresponding locid’s.

You can also find it out by the Weather.com website. After searching for and selecting you city, you will be sent to a url that will look something like, http://www.weather.com/outlook/driving/interstate/local/USTX0617?from=search_city, where USTX0617 is the locid.

Image Hosting

I’ve provided the images used and provided by weather.com here. If you want to host your own images, extract and upload the files, then, in the admin panel, edit the ‘Image Location’ field to point to your directory of images. Make sure to have the trailing slash.

If you don’t use your own images, you are free to use the ones that I’ve hosted, which are located at https://jamesdrakewilson.com/blog/weatherimages/

Editting display

You can edit ‘Widget Formatting’ to change how the info is displayed. To access the variables, use this formatting:

  • %loc% – Location
  • %temp% – Current temperature
  • %feels% – Feels like temperature
  • %icon% – The icon referring to the current weather. This is just a number
  • %iconhref% – The location of the image with your set image location at the front
  • %attribution% – The link supposedly required to be displayed. Weather data provided by weather.com®

The default formatting is:

<img src="%iconhref%" alt="%cond%" style="float:right;" />
%loc%<br />
<span style="font-size: 150%;">%temp% °F</span>
(%feels% °F)<br />
<span style="font-size: 65%; float: right;">%attribution%</a>

Download weather.zip


  1. I just keep getting a blank screen after I include the the non-plugin version in my header. I works fine when it’s on it’s own page. Any suggestions?

  2. i like the look of this plugin but i cant get it to work with my city
    this is where i’m at Temecula CA
    & i input all the info & it ends up showing some other city
    i have tryed eveything
    i’m going to have to go with wp-weather
    i’m sure this one will work

  3. Hi there: Thanks for the great widget.

    I would like to add several weather locations but the widget can just only be published once on my wordpress blog, what can I do?

  4. Hi James,

    I am unable to extract the images as they are in gzip format and I’m using Windows Vista.

    Can you provide me the same in zip file?


  5. Hi James,

    Just curious if I can modify the display city- weather.com displays my city as Midway Airport based on the zipcode when I really would like the location to display River Forest (a town about 10 miles from the airport it’s displaying). Can I manually change the city? Thanks!

  6. Hi James
    I installed your plugin, love it. Just one thing, I dont know if it has been mentioned before, but when I set the locid to my hometown (ie. UKXX0282 ) it shows the nearest observation station, and not the hometown. Its easy enough to change, you just replace:

    $start = strpos($cc,””) + 6;
    $loc = substr($cc, $start, strpos($cc, “”) – $start);


    // $start = strpos($cc,””) + 6;
    // $loc = substr($cc, $start, strpos($cc, “”) – $start);

    $placenamestart = strpos($data,””)+6;
    $loc = substr($data, $placenamestart, strpos($data, “”) – $placenamestart);

    Hope this helps someone.

  7. lol, wordpress is stripping the tags out automatically.

    the 2 lines starting // contain the obst tags and the 2 replacement lines contain the dnam tag.

    Clear as mud. Sorry.

  8. @Steve, you can also just change %loc% to your location by hand in the formatting section.

    I’ll look at it a bit more to see whats up with it. This might be newer behavior from the API.

  9. creating a website for a client. Not sure what happened, but weather temp will not show up. Uninstalled it and re-installed it several times. Dug into phpadmin to find where zip was being cashed. Deleted those lines of database, (I believe.) Not sure what is going on. Any ideas or help would be most appreciated.


    Thanks so much.

  10. I second Omar’s request for multiple location use of this widget. Can anyone give any hints or help? I tried creating separate directories and then using James’ php code (provided in earlier posts, the one to put in non-wp sites) to call it, but to no avail. Any help is appreciated, thanks!

  11. @Jason, could be file_get_contents problem. Try switching to cURL.

    @lisa, there’s been a lot of interest in multi-instance support. I just don’t have the time to work on something that makes me no money right now.

  12. Hi James, I want to thank you for this Plug in, It worked very good in my website, thanks and keep the good job.

  13. Thank you very much for this widget! With a little template tweaking it’s exactly what the majority of all bloggers want for a widget on their blogs.

    Just to let everyone else out there know; don’t feel bad about ripping off weather.com’s attribution link… Those bastards now make you sit through a DOZEN click-out-of-many-opt-in-‘speacials’ just to get the xml weather feed… On top of asking you 1,001 personal questions and getting you to join their list!

    I feel about as bad for removing their attribute link as I did when they shot Hitler. ๐Ÿ™‚

  14. Nice job, works well. Can I make the (clouds, etc, ) icons a little larger. I suppose I could upload new images.

  15. I will answer my own own question. I just made the following change:

    %loc%%temp% °F (%feels% °F)%attribution%

  16. Charles, I think Hitler shot himself, but I get what you’re saying. ๐Ÿ™‚

    James, I just installed WordPress 2.8, and I can’t edit the widget format field. I used the widget successfully in 2.7.1, so maybe this is a new problem with 2.8?

  17. Nevermind, I just can’t click in the format field and then type. If I tab to the field, it allows me to type.

  18. Hi James,
    I was wondering if the plugin can be modified to work with multiple instances on one site as introduced in WP 2.8.

    At this point it doesn’t show up among the available plugins once deployed in a sidebar.

  19. I can’t place the plugin by automatically, is it possible to do it by placing code in the place whre it must be show?

  20. Love the pluggin, but after I upgraded to PHP5 to get other pluggins functioning correctly..this one fails, any ideas?

  21. This widget had previously been working on a web site I’m building, but as of this morning, I’m not getting the weather data. Has a change been made on Weather.com’s end?

  22. Hi James,
    Thank you for your work on this plugin. It has worked fine for me and than all of a sudden the weather icon is showing as a “?”, and I am not getting the actual temperature. I have changed nothing in the structure of the template or database. Using WordPress 2.7.

    Thanks in advance – Sam

  23. Love the weather widget, but it stopped working this week. Weather.com no requires a prod parameter on the URI. I added a ‘&prod=xoap’ and it now works again.

  24. For some reason the weather widget isn’t displaying any feed data anymore. It just stopped 3 or 4 days ago, as if the weather channel read my post above and put a safeguard in their feed to make sure it’s not displayable when uncredited.

    (Perhaps they didn’t like the hitler crack? ๐Ÿ™‚

    Can someone test to see if that’s what it is? Nothing has changed on my site from when it was working perfectly 4 days ago, it just stopped showing the picture and the 2 numbers.


  25. Yeah this plugin stop working sometime last week and after experience the same problem with a simular widget (which is also grabbing the weather from weather.com) I found a solution for this problem.

    It seems weather.com has change there API and therefore the request for the xml files didn’t work anymore. You can fix it with simple adding a property in the request string.

    Open weather.php in your plugin folder and search for the line 56:
    $uri = ‘http://xoap.weather.com/weather/local/’…
    You will find a property “&link=XOAP” somewhere in the line, before the next Parameter simply add a “&prod=XOAP”, so it looks like:

    After saving the file the widget should start working again (May be you must deaktivate und activate the widget once?).

    May be the author could make a fixed version of the plugin sometime.

    Thanks for the nice widget
    Cheers Chiken

  26. Yup, it stopped working for me, too. I have it on two different wordpress installs, using two different weather.com accounts, and both stopped working about a week and a half ago.

  27. Updated. Works fine for me on a fresh 2.8 install. Let me know of any more problems. Sorry that it took me a while, been busy with schoolings and such.

  28. Complete & utter awesomeness. Thank you, James, for updating the plugin! It appears to be working 100% on my blog again.

  29. James,

    i still can’t figure out how to make the script reading my zipcode correctly. I enter in 92840 (garden grove) and 92802 (anaheim) but the script still comes up with Fullerton as the city.

  30. If it does the samething using the actual weather.com site, then that is just how they do it. You can manually change the name in the widget formatting.

  31. It’s still not working for me even after the update. I even deleted and reinstalled fresh, it’s using an old image location and basically won’t save any of the changes I try to make in the widget edit window.

  32. James, I am also having an issue where your widget displays a different city than what the weather.com web site displays. And I think I found something. Two examples: Zip 33609594 reads Tampa FL on weather.com, but your widget displays Tampa Intl Airport FL. And zip 33511 reads Brandon FL on weather.com but reads Tampa/Vandenberg FL.

    So, it seems to me what’s happening is that the Weather.com API is providing the name of the closest Airport, rather than the actual City. Or perhaps the API includes both the Airport name and the City name, and you are extracting the Airport name? Just a guess.

  33. OK, problem solved. You are pulling the name of the Observation Station (generally an airport) in XML variable (). Instead, I want to use the XML variable which is the name of the City equating to the zip code.

    I used Steve Franklin’s prior response and here is what I changed in weather.php:

    Locate the following section of code:
    // Location
    $start = strpos($cc,””) + 6;
    $loc = substr($cc, $start, strpos($cc, “”) – $start);

    And replace it with this:
    // Location
    $pnstart = strpos($data,””) + 6;
    $loc = substr($data, $pnstart, strpos($data, “”) – $pnstart);

    Hope this helps someone.

  34. @kweilbacher
    The same problem was in the previous version and I had the same solution. However, when you try to post to the blog, it strips the tags from the “”. The tag you need to replace is the observation station (obst) with location (loc). remember to use less than and greater than signs instead of curly brackets.

    Also, the temperature always says degrees F even when displaying a centigrade scale. I got a fix for that somewhere too. Unfortunately I upgraded my wordpress site, and now its moaning about not enough memory.

  35. James, this is a really GREAT plug-in, and I was happy to find it a few months back. I have two questions for you;

    1. The same as @Migue posted on July 24, is there a way to place more than one (1) weather widget at the same time ?? I use my website for travel blogging for friends and family. We cruise quite a bit, so having multiple “destinations” of where we are headed with the weather currently at that location is a GREAT TEASER ๐Ÿ™‚

    2. How do I UN-INSTALL an existing plug-in (ie. I currently have v1.5 installed). I have an Ubuntu installation – which is my primary O/S, and I am running WordPress v2.7.1 at the moment. I would like to update your current plug-in to v1.6 and I’m not sure if I should simply download the new one and “over-write” the existing folder on my file system, or De-activate the current plug-in, THEN delete the folder and it’s contents and download – then install the new version.

    I am a little bit of a “newbie” with Ubuntu / Linux – but have some previous Linux background years ago, so please be specific if you could when describing how to go about updating plug-ins.

    THANKS so much in advance, and again, love this plug-in you created !


  36. James, why did you remove my question & comment to you from a couple of days ago ???

    I had stated that I really enjoyed this plug-in and have found it very useful to my particular website and what we blog about.

    As “Migue” had asked on July 24th in the last post before mine, I too am also VERY INTERESTED in whether or not you are going to provide the capability to allow multiple cities (or widgets / plug-ins) to broadcast weather for a particular destination.

    Since we blog about travel (for the benefit of friends and family) I think this is a great suggestion since we can then post the weather for the places we are heading to — as a “teaser” to those who can’t travel with us ๐Ÿ™‚

    Can you please comment, and thanks in advance.


  37. In answer to those wanting multiple instances of the widget…
    I bodgied this by:
    – Creating a new directory called weather-widget2 under plugins
    – Put James’ PHP code in there
    – Replaced all instances of widget_weather to widget_weather2 in the code
    – Replaced all instances of widget_weather to widget_weather2 in the code

    Activate and you now have a 2nd widget to choose and display on your blog.

    It might not be the right way to do it, but it works for me.
    See: http://aldo.hartog-walker.com

  38. To anyone looking for their comments and not seeing them, sorry. Never installed sendmail on this server, so I never got the pending comments emails.

    And to install the new version, you just overwrite the old file.

  39. Hey,

    first of all, sry for my bad English. ๐Ÿ™ I hope you’ll unterstand me…
    I wanted to ask, if it’s very difficult to integrate the local time behind the location. In your screenshot above “Katy, TX (04:37 AM)”. Could you tell me, how to do this?

    Thank you in advance.