FairWeather
FairWeather is a lightweight WordPress plugin that displays the current weather in a simple two-line format using a shortcode.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/kemtopher/fair-weather/archive/refs/heads/main.zipFairWeather is a lightweight WordPress plugin that displays the current weather in a simple two-line format using a shortcode.
- Line 1: location (
City, State, Country Code) - Line 2: weekday + date + current temperature (for example:
Tues. 4 72°F)
It is designed for theme areas like headers, widgets, and Elementor containers where a compact weather block is needed.
Build Overview
This plugin is a classic PHP WordPress plugin with no build steps.
Core parts:
fair-weather.php: plugin bootstrap, constants, activation defaults, hooksincludes/class-settings.php: Settings API registration and admin menu pageadmin/settings-page.php: settings page UIincludes/class-weather-client.php: location resolution + weather API calls + cachingincludes/class-shortcode.php: shortcode rendering and scoped/global style injectionassets/frontend.css: default front-end styles
Dependencies
Runtime Requirements
- WordPress
6.0+ - PHP
7.4+
External APIs
- OpenWeatherMap
- Required for geocoding and current weather data
- You must provide your own API key in plugin settings
- ip-api.com
- Used server-side for visitor IP geolocation when no shortcode location override is provided
Internal/Platform Dependencies
- WordPress Settings API
- WordPress Shortcode API
- WordPress HTTP API (
wp_remote_get) - WordPress Transients API (
get_transient/set_transient)
Installation
- Place the plugin folder in
wp-content/plugins/. - Activate FairWeather in WordPress Admin.
- Go to
Settings -> FairWeather. - Add your OpenWeatherMap API key.
- Configure defaults (location, unit, optional global CSS).
- Insert shortcode
[fairweather]where you want output.
Plugin Settings
Open: WordPress Admin -> Settings -> FairWeather
1) OpenWeatherMap API Key
- Field: OpenWeatherMap API key
- Get a key from: https://openweathermap.org/api
- This key is required for weather/geocoding requests.
2) Default Location
- Field: Default location
- Example:
Atlanta, GA - Used as fallback when IP geolocation is unavailable or fails.
3) Default Temperature Unit
- Field: Default temperature unit
- Options:
FahrenheitCelsius
4) Global Custom CSS
- Field: Global custom CSS
- Optional CSS rules loaded on pages where the shortcode appears.
- Useful selectors:
.fairweather.fairweather__location.fairweather__meta.fairweather__temp.fairweather__error
Shortcode Usage
Base shortcode:
[fairweather]
Shortcode Attributes
location(optional)- City/region string, or lat/lon format:
"33.7490,-84.3880" - If omitted, plugin tries IP geolocation, then falls back to the default location setting.
- City/region string, or lat/lon format:
unit(optional)forc- If omitted, uses the admin default unit
class(optional)- Additional CSS classes added to wrapper
css(optional)- Scoped declaration block applied to this shortcode instance
Examples:
[fairweather location="Atlanta, GA"]
[fairweather unit="c"]
[fairweather location="33.7490,-84.3880" class="header-weather"]
[fairweather css="font-size:14px;color:#fff;"]
How Location Is Resolved
Resolution order:
- Shortcode
locationattribute (if provided) - Visitor IP geolocation
- Default location from plugin settings
When IP is private/local (common in local development), it skips IP geolocation and uses the default location.
Caching and Performance
- Current weather values are cached via WordPress transients for
20 minutes. - Cache key includes rounded coordinates and units.
Notes
- This plugin outputs weather server-side at render time.
- If API key is missing or API calls fail, an error message is rendered in the shortcode output.