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

Today Aug 15th
Isolated rain showers between 2pm and 3pm. Mostly sunny, with a high near 82. Northeast wind 0 to 5 mph. Chance of precipitation is 20%.

Tonight
Patchy fog after 4am. Partly cloudy, with a low around 55. Northeast wind 0 to 5 mph.

Tuesday Aug 16th
Mostly sunny, with a high near 80. Northeast wind 0 to 10 mph.

Tuesday Night
A slight chance of rain showers after 11pm. Mostly cloudy, with a low around 59. Northeast wind 5 to 10 mph.

Wednesday Aug 17th
A chance of rain showers. Mostly cloudy, with a high near 73. North wind 5 to 10 mph. Chance of precipitation is 40%.

Wednesday Night
A chance of rain showers. Mostly cloudy, with a low around 57. Chance of precipitation is 40%.

Thursday Aug 18th
A slight chance of rain showers before 2pm. Mostly sunny, with a high near 77.

Thursday Night
Mostly clear, with a low around 56.

Friday Aug 19th
Sunny, with a high near 84.

Friday Night
Mostly clear, with a low around 59.

Saturday Aug 20th
Mostly sunny, with a high near 87.

Saturday Night
Mostly cloudy, with a low around 61.

Sunday Aug 21st
A slight chance of rain showers after 2pm. Partly sunny, with a high near 83.

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.