Custom weather plugin
Repository for WordPress weather plugin with dynamic api key and city name.
by Kaushik Bhalodiya · github.com/kaushikbhalodiya/wordpress_weather_plugin
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/kaushikbhalodiya/wordpress_weather_plugin/archive/refs/heads/main.zipReadme
WordPress Weather Api Based Widget Plugin
A Simple wordpress plugin to bind openweathermap.org API and get the weather info based on give city name. User can direcly add this plugin and with using shortcodes user need to pass weatherapikey key={API KEY} to link plugin with your generate openweathermap.org API key then pass weather city={city name} so plugin direcly call api and get weather info of the give city name.
Features
- Display weather information using shortcodes
- Fetches real-time weather data from the api
- Uses the WordPress HTTP API (
wp_remote_get) - Caches API responses for 1 hour using the Transients API
- Sanitizes user input to secure the data flow
- Object-Oriented PHP codeing structure
Requirements
- WordPress 7.x+
- PHP 7.4+
- OpenWeatherMap API Key
Installation
-
Copy the plugin file to:
wp-content/plugins/{your custom plugin folder name}/ -
Activate the plugin from WordPress Admin → Plugins.
-
Add new page and get shortcode and add 2 shortcodes info
[weatherapikey key="{your API KEY}"] [weather city="nasik"]
How Caching Works
The plugin uses the WordPress Transients API.
- On the first request, the plugin calls the weather API.
- The response is cached for one hour.
- Future requests use the cached data until it expires.
- After one hour, the API is called again automatically.
Technologies Used
- PHP
- WordPress Plugin API
- WordPress Shortcodes
- WordPress HTTP API
- WordPress Transients API
- OpenWeatherMap API
Author
Kaushik Bhalodiya