Skip to Content
✨ v1.13.0 Released - See the release notes

Shortcode

Bannerize provides several shortcodes for displaying banners in posts, pages, widget areas, or anywhere WordPress processes shortcodes. The primary shortcode is [wp_bannerize_pro], with specialized variants for device targeting and geolocation.

Primary Shortcode

[wp_bannerize_pro]

Without any attributes, this displays all published and active banners.

Attributes

AttributeTypeDescriptionDefault
idintegerDisplay a specific banner by its post ID
numbersintegerMaximum number of banners to showAll
campaignsstringFilter by campaign slug(s), comma-separatedAll
orderbystringSort order: menu_order, impressions, clicks, ctr, randommenu_order
orderstringSort direction: ASC or DESCDESC
layoutstringDisplay layout: vertical or horizontalvertical
rank_seedintegerCustom seed for randomization consistency
mobilebooleanShow only on mobile devices: true or false
desktopbooleanShow only on desktop devices: true or false
post_categoriesstringShow only on posts in these categories (comma-separated slugs)

Examples

Display a Specific Banner

[wp_bannerize_pro id="42"]

Display Banners from a Campaign

[wp_bannerize_pro campaigns="sidebar-ads"]

Display Multiple Campaigns

[wp_bannerize_pro campaigns="header-ads,footer-ads"]

Limit Number of Banners

[wp_bannerize_pro campaigns="holiday-sale" numbers="3"]

Random Order

[wp_bannerize_pro campaigns="sidebar-ads" numbers="1" orderby="random"]

This displays one random banner from the “sidebar-ads” campaign on each page load.

Horizontal Layout

[wp_bannerize_pro campaigns="header-ads" layout="horizontal"]

Displays banners side by side instead of stacked vertically.

Sort by Performance

[wp_bannerize_pro orderby="clicks" order="DESC" numbers="5"]

Shows the top 5 most-clicked banners.

Sort by CTR

[wp_bannerize_pro orderby="ctr" order="DESC" numbers="3"]

Shows the 3 banners with the highest click-through rate.

Consistent Randomization with rank_seed

[wp_bannerize_pro orderby="random" rank_seed="12345"]

The rank_seed attribute provides a consistent random order for the same seed value. This is useful when you want the same “random” arrangement to persist across page loads or for A/B testing.

Filter by Post Category

[wp_bannerize_pro post_categories="technology,gadgets"]

This banner will only display when the current post belongs to the “technology” or “gadgets” categories. On all other posts, the shortcode outputs nothing.

Device-Specific Shortcodes

Bannerize provides dedicated shortcodes for targeting specific device types:

[wp_bannerize_pro_mobile campaigns="mobile-ads" numbers="1"]

This shortcode only renders on mobile devices. It accepts all the same attributes as [wp_bannerize_pro].

Device detection uses the mobile and desktop attributes internally. The dedicated shortcodes are convenience wrappers — you can achieve the same result with [wp_bannerize_pro mobile="true"] or [wp_bannerize_pro desktop="true"].

Geolocation Shortcode

Target banners by visitor country using the geo shortcode:

[wp_bannerize_pro_geo countries="US,UK,CA" campaigns="english-ads"]
AttributeDescription
countriesComma-separated list of ISO 3166-1 alpha-2 country codes

The geo shortcode accepts all the standard [wp_bannerize_pro] attributes in addition to countries.

Geolocation requires an IPStack API key configured in Bannerize > Settings > Geolocalization. Without a valid API key, the geo shortcode will not filter by country and will display banners to all visitors.

Geo Shortcode Examples

Display different banners for different regions:

[wp_bannerize_pro_geo countries="US" campaigns="us-promotions"] [wp_bannerize_pro_geo countries="DE,FR,IT,ES" campaigns="eu-promotions"] [wp_bannerize_pro_geo countries="JP" campaigns="japan-promotions"]

Combining Attributes

You can combine multiple attributes for precise control:

[wp_bannerize_pro campaigns="sidebar-ads" numbers="2" orderby="random" layout="vertical" desktop="true" post_categories="news"]

This displays 2 random vertical banners from the “sidebar-ads” campaign, only on desktop devices, and only on posts in the “news” category.

Using in Widget Areas

Shortcodes work in WordPress text widgets. Add a Text or Custom HTML widget to any sidebar or widget area and paste the shortcode:

[wp_bannerize_pro campaigns="sidebar-ads" numbers="3"]

For a more user-friendly widget experience with a graphical interface, consider using the dedicated Bannerize Widget instead.

Shortcode in PHP Templates

To use the shortcode in a PHP theme template:

echo do_shortcode('[wp_bannerize_pro campaigns="footer-ads" numbers="2"]');

However, for theme templates, the dedicated PHP functions are recommended as they offer better performance and type safety.

Last updated on