WordPress Weather Widget

Plugins

Important update: Google have switched off their weather API

I must have a weather forecast on my site!!

Anonymous Client

Extended mode display

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

The weather widget form

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

  1. Hello !
    I’m working on the website provided above xD
    I’m searching for a weather plugin, but i’d like the every user could choose his own location to check xD
    Is there any way to achieve this goal with your plugin or you know how to,or where can i get that ?

  2. Love the plugin, thanks, seeing that it’s free even if you don’t adapt it to the new API I’m grateful to have the code and will use it with another set of images pulled in from the alt data.

  3. PS I have WP 3.4.2; is this a problem?

  4. I get HTTP error 403 when the widget searches the data source.

    1. Hi Kevin, check the top of the blog post – there’s a link with more information. Google discontinued their weather API so the plugin no longer works.

Leave a Reply

Your email address will not be published. Required fields are marked *