Important update: Google have switched off their weather API
I must have a weather forecast on my site!!
Anonymous Client
You may well have heard these exact words, or at least something similar. We certainly did but found many of the weather widgets and badges out there lacking. Either they were not aimed at regular users (having to track down your own locid for non-US addresses for example) or they had rate limits on the API.
We had tried using the Yahoo weather badge at first however as soon as traffic to our client’s site increased the widget would become unavailable before lunch time due to exceeding the limits. As a result we decided to put together our own simple weather widget that would never be unavailable by using cached data from the Google Weather API.
Download
The weather widget is available from the WordPress.org repository for download and installation. You can also see download stats.
Installation
Copy the contents of the zip file to your plugins directory. Proceed to the plugins page and activate the ICIT Weather Widget. Alternatively, use the automatic download and install available from the plugins page of your WordPress back-end.
Please note you will need a theme that supports dynamic sidebars.
Usage
Go to the widgets page. There you will find the multi-use ICIT Weather Widget. Drop it into a sidebar to get started. You will be presented with the form to configure the widget.
- Title
The title is optional but will override the display of the location if set. - Country
Choose the country you want to look at the weather in. - City, town, postal or zip code
Use this field to narrow down the search some more, for example putting in ‘L1’ or ‘Liverpool’ will get the weather information for that location. - Widget display
Choose from a compact or an extended display mode. In extended mode the full weather forecast for the current day is shown including humidity and wind conditions. In compact mode you get a small icon, the day name and the temperature range for the day. - Show forecast for…
You can show up to an extra 3 days of weather forecasts in their compact form after the current day. - How often to check the weather
Set a timer in minutes for how often the widget should poll the API for updated weather information. Default is 60 minutes. - Show temperature in Celsius
This should be fairly obvious! Toggle between displaying degrees farenheit and degrees celsius. - Output CSS
Toggle the default styling on or off for the widget instance. - Show Interconnect/IT credit link
The plugin is free so we appreciate the support and traffic the credit link can drive our way but you can switch it off if you prefer.
Feedback / Suggestions / Bugs?
If you have any comments, suggestions or feature requests leave them below. Please remember we can only fit the work in as time permits so only the most requested or useful features will go in. The aim is to keep the widget simple.
We would also like to hear if you find any bugs while using the plugin so we can rectify them.
Please DO NOT email us for support unless you are a paying customer – we will no longer reply.
Update:
With the latest version of the weather widget we have solved a few key problems:
- Localisation
- Bug when calculating forecast temperatures for certain countries
- Added filters to avoid having to edit the core plugin when google change their API
It’s not 100% but if your WordPress installation has the WPLANG constant defined anywhere or if you have a ‘locale’ filter in your theme or a plugin then the API will return temperature data and weekdays in the specified language. We still need translations for the rest of the plugin if anyone is inclined to help us out with that.
Filters
Here are the filters with example uses that the plugin now gives you to play with. Generally they shouldn’t be needed but it means we can easily patch the plugin if the google API changes suddenly.
icit_weather_widget_images
Filters the images array. Use this if you want different icons or if google change their image file names.
function new_weather_images( $images ) { $images['sunny'] = 'my-icons/sunny.png'; return $images; } add_filter('icit_weather_widget_images', 'new_weather_images');
icit_weather_widget_check_image
An alternative place to alter image paths. Parameters are the image url returned from google, an array of the icon filename and file extension and lastly a boolean to say whether the request is for a thumbnail or not.
function new_weather_check_image( $image, $icon, $thumb ) { return array( 'src' => get_stylesheet_directory_uri() . '/images/' . $icon[ 'filename' ], 'key' => $icon[ 1 ] // keep this the same ); } add_filter('icit_weather_widget_check_image', 'new_weather_check_image');
icit_weather_widget_na_icon
If you only want to change the N/A icon you can use this filter to choose an alternative image as the fallback if you prefer a ‘best guess’ approach eg. using the icon for clear weather.
function new_weather_check_image( $image ) { return 'clear.png'; } add_filter('icit_weather_widget_na_icon', 'new_weather_na_icon');
icit_weather_widget_locale
This shouldn’t really be needed as the plugin looks at the WPLANG
constant but if you do run into problems with what google returns from their API you can patch the locale string used to retrieve the weather data.
function new_weather_locale( $locale ) { return 'fr'; // french weather data } add_filter('icit_weather_widget_locale', 'new_weather_locale');
Note with the above you could also use the general ‘locale
‘ filter in WordPress however the effect of that is site-wide and may not play too nicely with poorly written plugins/themes.
192 responses to “WordPress Weather Widget”
404 error not open my computer also web link
Hi folks. Google have killed their weather API so in the meantime I recommend using http://wunderground.com widgets until we can implement their API.
Sorry for the inconvenience 🙁
i search the link that you recomment . is there wordpress plugin on the link. or for easy can you juss give the plugin detail. anyway hope you will be back soon . iyour plugin was easier one and better . thanks.
Hi yes there is, a quick google search pointed me to this plugin which actually looks as good if not better than ours! http://wordpress.org/extend/plugins/wunderground/
thanks gfor you reply robert will check it out.
Here is the source of the current problems, I believe: http://www.gizmodo.com.au/2012/08/google-silently-kills-popular-api-breaks-weather-apps-everywhere/
Is there anyway you can use a different weather API so the widget will work again? I love your weather widget so much!
hmmm…must be doing something wrong..i can’t get it to show Brisbane, Australia. 🙁
Mine has locked in on Monday
and also can’t display new widgets set ups
Been fine for 10months or so up until recently
Like the poster below.. This plugin worked great for a few days, now it has stopped working. Error message of:-
The last error occured at “August 30, 2012 7:25 am” with the message “HTTP response code 403”.
How to I resolve this error?
Does resaving the widget help? It might be that google has changed the API in some way. We’ll look into it.
widget worked great in the beginning. Now it doesn’t show up anymore in my sidebar. ICIT widget says “String could not be parsed as XML”.
What should I do next to solve this problem??
Looks like a hot weekend ahead!
Hi, great widget! I’m stuck on a time server issue that may be something to do with wordpress (am new to this all) – even though i change the current local time in the wp settings, the widget still shows the UTC time which is 10hrs earlier. I’ve re-set and re-installed everything but can’t seem to fix it… any help would be greatly appreciated. Cheers!
Hi, the widget look very nice, there is a way that i can change de colors of the fonts?