WordPress Custom Plugin: NOAA Weather Forecast

I built a WordPress plugin for displaying the weather forecast. The forecast data is pulled from the NOAA NWS Forecast API. The plugin has a shortcode that can be placed on a post, page, or in a widget, anywhere you want to show the forecast.

The shortcode takes two perimeters:
1) the location (as latitude, longitude), and
2) the number of days to show. Something like this
[ weather location="43.0237,-71.6023" days="4" ]

The plug has a separate template file that can be customized to change the look of the forecast.

The plugin has built-in cache management. Caching prevents it from hit NOAA’s API every time the forecast is requested. If you hit the API too often NOAA may kick you off. The cache duration is configurable. A 6 hour cache works well for general use.

So here is the shortcode in action. It will grab NOAA’s 7 day forecast for my neighborhood (43.0237, -71.6023)

Goffstown, NH

Tonight
Partly cloudy, with a low around 60. West wind 0 to 5 mph.

Sunday Jul 3rd
Sunny, with a high near 82. Northwest wind 5 to 10 mph.

Sunday Night
Clear, with a low around 55. West wind 0 to 10 mph.

Independence Day Jul 4th
Sunny, with a high near 81. Northwest wind 0 to 5 mph.

Monday Night
A slight chance of rain showers after 2am. Mostly cloudy, with a low around 59. West wind 0 to 5 mph.

Tuesday Jul 5th
Rain showers likely. Mostly cloudy, with a high near 74. Chance of precipitation is 70%.

Tuesday Night
Rain showers likely. Mostly cloudy, with a low around 58. Chance of precipitation is 70%.

Wednesday Jul 6th
A chance of rain showers. Mostly sunny, with a high near 77. Chance of precipitation is 30%.

Wednesday Night
A slight chance of rain showers. Mostly clear, with a low around 55.

Thursday Jul 7th
A slight chance of rain showers. Mostly sunny, with a high near 80.

Thursday Night
A slight chance of rain showers. Partly cloudy, with a low around 59.

Friday Jul 8th
A chance of rain showers. Mostly sunny, with a high near 81. Chance of precipitation is 30%.

Friday Night
A chance of rain showers. Partly cloudy, with a low around 59. Chance of precipitation is 30%.

Published by

Kimball

Kimball is a website designer and developer in Goffstown, NH.

One comment on:
“WordPress Custom Plugin: NOAA Weather Forecast”

Leave a Reply

Your email address will not be published.