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. English:
    Hello I have problems when I want to translate the language of the plugin, from English to Spanish, there is some version of the plugin in Spanish? because they try to translate (I find the days and many other words to make it complete), the climates and is not translated then the web … there is something in Spanish of this plugin?

    Spanish:
    Hola tengo problemas cuando quiero traducir el lenguaje del plugin, del ingles al español, exíste alguna version del plugin en español? porque intente traducir (no encuentro los días y muchas otras palabras para hacerlo completo), los climas y no se ve traducido luego en la web… hay algo en español de este plugin?

  2. here..new wordpress plug-in..

    u can display 4 days weather forecast and current date and time of your city or any other cities..

    http://wordpress.org/extend/plugins/weather-and-time/

  3. I just loaded your Weather Widget into WordPress 3.3.2 and yes, so far it is functioning 100%. Thanks.

  4. Hi There,

    Just added your weather plugin on our test site before we go live. I just wanted to suggest having a metric/imperial toggle versus selecting Celsius option only. For example I cannot understand what 5 mph wind speed really is…must be breezy? lol. Nice to have the Celsius function but entirely metric would be awesome. Thanks for a great looking plugin!

    Leo

  5. I am unable to get the widget to change from the default (English) using WPML language switcher. I’ve put a translated .mo file in the plugin’s lang folder but it appears something is missing to trigger the language switch. Any suggestions? (I’m using the Hybrid News theme. )

  6. You asked for feedback / suggestions…

    Your weather widget looks so promising, but I need to show more than one location in a side bar, and …

    I would VERY much like to have a SHORT CODE implementation so I could put weather specific to a locale in a post or page.

    Thanks for listening! 🙂

  7. as changing the language to Spanish

  8. Hi Great weather widget. Is there any way the icons can show its night time. i.e. with moon and clouds etc depending on the conditions?

  9. Cheer it s nice weather widget still need One detail (Language) Ex French.
    ty for widget.

Leave a Reply

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