Manage banners across WordPress Multisite

Published Updated 3 min read

Multisite networks often need the same banner in the same place on every sub-site: a seasonal sale header, a network-wide notice, a sponsor placement. Updating each site by hand works until there are twenty sites and the same banner lives in thirty widget areas.

The plugins that solve it tend to be full ad servers with CPM dashboards and reporting, or general ad managers where Multisite support arrived late. What most network operators need is smaller: create a banner once on the main site, drop a shortcode on any sub-site, and change it in one place when the campaign ends.

Multisite keeps every site in one shared database, so a shortcode on a sub-site can read the main site's options directly. No sync job, nothing to keep in step.

One library of banners on the main site

The manage page appears in the admin menu on the main site only. A form takes a name and an HTML body; below it, every saved banner is listed with its name, a copy-ready shortcode and a delete button.

The name becomes the shortcode attribute: a banner called header-sponsor is [network_banner name="header-sponsor"]. That works in a Shortcode block, a Text widget, or a template via do_shortcode, on any site in the network. Different sub-sites can show different banners from the same library, and editing a banner on the main site updates it everywhere it appears.

Banners are stored as a JSON array in one row of the main site's wp_options. No custom tables and no migration.

How sub-sites read banners from the main site

Each site has its own table prefix (wp_2_options, wp_3_options and so on), and WordPress provides switch_to_blog() to read another site's data for a moment. The shortcode calls switch_to_blog(get_main_site_id()), reads the network_banners option, then calls restore_current_blog() before returning.

That is one database query per shortcode on the page. With a persistent object cache like Redis, the option is cached and the query does not run on most requests.

An unknown name returns an empty string, so a typo shows as a blank space, not an error, and so does a deleted banner. Before deleting one, search the sub-sites' widgets, posts and templates for its name.

What survives the HTML field

The field is saved and output through wp_kses_post, the same filter WordPress applies to post content. Images, links, headings, inline styles, figure elements and most HTML5 tags pass; script tags do not.

Most direct sponsor placements are an image wrapped in a link, which works as is. Ad tags from Google AdSense or Carbon Ads usually carry an inline script: the image and link survive, the script is stripped. For tags that need JavaScript, a follow-up build can enqueue the script separately and use the banner field for the container only.

Impressions, rotation and scheduling need an ad server

Nothing here counts impressions, tracks clicks, rotates creatives, schedules banners between dates or targets by site or audience. Advanced Ads supports Multisite and covers all of that. Broadstreet is built for local media networks on Multisite and handles programmatic inventory, and Google Ad Manager is the tool for programmatic at scale.

The shape this fits is a few banners managed by hand and shown consistently across the network: a university posting a term-break notice across department sites, a franchise network sharing a seasonal campaign, an agency running a network of client sites. A news network selling CPM inventory is not that shape.

What you get

Included

  • Admin screen on the main site to create, name, and delete banners
  • A [network_banner name="..."] shortcode that works on every sub-site in the network
  • Banner content stored in the main site's options table, read by sub-sites via switch_to_blog
  • wp_kses_post filtering on both save and output

Not included

  • Impression counting or click-through tracking
  • Scheduling banners to show between specific dates
  • Rotating between multiple creatives for the same placement
  • Per-site overrides or excluding specific sub-sites from a banner
  • JavaScript-dependent ad tags such as full AdSense embed codes

Advanced Ads does the things on the right. This build covers the part most sites use.

Questions

Do I need super admin access to add banners?

No. The manage screen needs manage_options on the main site, which on a standard network means the main site's administrator. Super admins have it automatically, but a main-site admin can manage banners without network-wide access. Someone without any admin access on the main site cannot.

Can I use it on a single-site install?

The shortcode works, and the admin screen appears because the only site is the main site, but the switch_to_blog path is never used. On a single site, a Text widget or hard-coded HTML is simpler.

Build it in Steem

The button opens the builder with this guide's prompt filled in, so you can change anything before it runs. Nothing is built, and nothing is charged, until you send it.

Build this pluginAbout 55 credits. The free plan includes enough for one.
Read the prompt (317 words)

Build a WordPress plugin called Network Banner Manager. Plugin Name: Network Banner Manager. Description: Manage shared HTML banners on the main Multisite site and display them on any sub-site via shortcode. Single PHP file. No dependencies. On admin_menu: if is_main_site(), add a top-level admin menu page with page title "Network Banners", menu title "Network Banners", capability "manage_options", slug "network-banners", callback render_network_banners_page. Store banners in the main site's options table under the key "network_banners" as a JSON-encoded array. Each element: id (integer), name (string), html (string). Register two admin_post actions, both using check_admin_referer: admin_post_save_network_banner: read POST banner_name and banner_html. Sanitize banner_name with sanitize_text_field, banner_html with wp_kses_post. Load existing banners via get_option("network_banners", "[]"), json_decode to array. Compute next id as max existing id + 1 (or 1 if array is empty). Append new entry. json_encode and update_option. wp_redirect to the manage page and exit. admin_post_delete_network_banner: read POST banner_id (intval). Load banners, filter out the entry with that id, update_option. wp_redirect to manage page and exit. render_network_banners_page: output h1 "Network Banners". Output add-banner form (method POST, action admin_url("admin-post.php"), hidden field action=save_network_banner, wp_nonce_field("save_network_banner")): text input name=banner_name (label "Name", required, placeholder "e.g. header-sponsor"), textarea name=banner_html (label "HTML", rows=4, required), submit button "Add Banner". Below the form, load banners and output an HTML table with columns: Name, Shortcode, Delete. Shortcode column: a code element containing the literal text [network_banner name="{name}"]. Delete column: form with method POST, action admin_url("admin-post.php"), hidden fields action=delete_network_banner and banner_id={id}, wp_nonce_field("delete_network_banner_{id}"), submit button "Delete". If no banners exist, output a p "No banners yet." Register shortcode tag "network_banner". Accept attribute "name" (default empty string), sanitized with sanitize_text_field. If name is empty, return empty string. If is_main_site(): $banners = json_decode(get_option("network_banners", "[]")). Else: switch_to_blog(get_main_site_id()), $banners = json_decode(get_option("network_banners", "[]")), restore_current_blog(). Find first entry where entry->name === $name. If found, return wp_kses_post(entry->html). Else return empty string. No settings page beyond the manage screen. No AJAX. No JavaScript. No frontend CSS. No custom database tables.