How to add weather forecasts to a WordPress site
You can add a weather forecast to WordPress with an embeddable weather widget, a custom API integration, or a shortcode plugin. A Custom HTML block is fine for one fixed location, while a plugin is quicker when you need forecasts in several places.
- 01Choose the forecast format
- 02Add an embeddable widget manually
- 03Build a custom API display
- 04Install a shortcode weather plugin
- 05Place and style the forecast
- 06Test the live result
What you need
- A WordPress site with administrator access
- The location or coordinates you want to show
- A weather provider account or embeddable widget code
- A backup or staging copy if adding custom code
Choose the forecast format
Decide whether you need current conditions, an hourly forecast, a multi-day forecast, or all three. Also choose the location, temperature unit, language, and where the forecast should appear.
For one fixed location, an embedded widget is usually enough. If you need several locations, custom styling, or a forecast reused across templates, use an API-based integration or a plugin.
Add an embeddable widget manually
Use a weather provider that gives you official embed code, then copy that code from the provider’s dashboard. In WordPress, open the page or post, add a Custom HTML block, and paste the code. You can also place suitable HTML in a widget area if your theme provides one.
WordPress supports Custom HTML for adding code, but users without the required HTML capability may have disallowed tags such as <script> or <iframe> removed when the content is saved.
Build a custom API display
For full control, create a small custom plugin or child-theme integration that requests forecast data from your weather provider and renders it in a template or shortcode. Use geographic coordinates where possible because they avoid ambiguous city names. OpenWeather’s documented forecast endpoint accepts latitude, longitude, an API key, and unit settings.
Make the request on the server with WordPress’s HTTP API, such as wp_remote_get(), and cache successful responses with the Transients API. Do not request fresh weather data on every page view, or a busy site can become slow and the provider may reject excessive requests.
Install a shortcode weather plugin
For most site owners, the quicker route is a weather plugin that provides a shortcode, widget, or block. Install the plugin from Plugins in the WordPress dashboard, or upload its ZIP file, then activate it.
Enter the location, choose Celsius or Fahrenheit, select current conditions or forecast ranges, and save the settings. A shortcode-and-widget plugin is useful when you want to place the same type of weather display in posts, pages, sidebars, or footer areas without maintaining API code.
Place and style the forecast
Add the generated shortcode to a Shortcode block, a page, a post, or a widget area. If the plugin provides a widget, add it under Appearance and then Widgets, or in the Site Editor’s widget or template area.
Check the display at the width of your content column, not just on a desktop screen. Long location names, forecast icons, and hourly rows commonly overflow narrow sidebars, so reduce the number of visible forecast periods or add responsive CSS.
Test the live result
View the page while logged out and check the forecast on a phone, tablet, and desktop. Confirm the location, unit, update time, icons, attribution requirements, and daylight-saving time handling.
If the display is blank, check the API key, provider quota, coordinates, browser console, caching layer, and firewall logs. A missing or invalid key can also cause repeated uncached requests, which may slow page generation.
If you want the fast route without writing API code, use Simple Weather WordPress Shortcode and Widget. It provides shortcode and widget placement for current conditions and forecasts, location settings, unit options, and responsive output.
Let Simple Weather WordPress Shortcode and Widget do it
Shortcode and widget approach for current conditions and forecasts, ideal when you need simple location-based weather displays.
Sources
- wordpress.org /documentation/article/custom-html/?utm_source=openai
- openweathermap.org /api/forecast5?utm_source=openai
- developer.wordpress.org /plugins/http-api/?utm_source=openai
- wordpress.org /support/topic/http-requests-to-api-openweathermap-org-when-…
Questions
- Can I add a weather forecast without a plugin?
- Yes, you can add an embeddable weather widget through a Custom HTML block, provided the provider supplies embed code and your WordPress user account is allowed to save that markup. This works well for one fixed location. For multiple locations or custom forecast layouts, you will need either a coded API integration or a plugin.
- Why did WordPress remove my weather script or iframe?
- WordPress can remove script or iframe markup when the user saving the page does not have the required unfiltered HTML capability. A security plugin, hosting firewall, or content security policy can also block the embed. Ask an administrator to check permissions, then review firewall logs before repeatedly pasting the code.
- Should the weather API request run in the browser or on the server?
- A server-side request is usually safer when it uses a private API key, and WordPress can cache the response before displaying it. A browser-side widget can be acceptable when the provider intentionally supplies public embed code. Never expose a private key in page source, and cache forecast responses rather than requesting them for every visitor.
- Why is my weather forecast showing the wrong city?
- The wrong city usually comes from an ambiguous name, an incorrect country or state, or inaccurate coordinates. Use the provider’s geocoding tool to find the latitude and longitude, then save those coordinates instead of relying on a city-name search. Check the displayed location and timezone after saving the settings.
- What is the fastest way to add forecasts in several places?
- A shortcode and widget plugin is the fastest practical option for several posts, pages, sidebars, or footer areas. Configure the location and units once, then insert the shortcode wherever needed or add the widget to the required areas. This avoids maintaining API requests, caching, and responsive markup yourself.