PHP Function
Bannerize provides two PHP functions for displaying banners directly in your theme templates. These functions give you the most control and are the recommended approach when working in PHP theme files.
Functions
wp_bannerize_pro()
Outputs the banner HTML directly (echoes to the page).
wp_bannerize_pro($args);get_wp_bannerize_pro()
Returns the banner HTML as a string without outputting it. Useful when you need to manipulate the output before displaying it.
$html = get_wp_bannerize_pro($args);Arguments
Both functions accept a single associative array with the following keys:
| Argument | Type | Description | Default |
|---|---|---|---|
id | int | Display a specific banner by its post ID | — |
numbers | int | Maximum number of banners to display | All |
campaigns | string | Campaign slug(s), comma-separated | All |
orderby | string | Sort order: menu_order, impressions, clicks, ctr, random | menu_order |
order | string | Sort direction: ASC or DESC | DESC |
layout | string | Display layout: vertical or horizontal | vertical |
rank_seed | int | Custom seed for consistent randomization | — |
mobile | bool | Show only on mobile devices | false |
desktop | bool | Show only on desktop devices | false |
post_categories | string | Show only on posts in these categories (comma-separated slugs) | — |
Examples
Display All Banners
<?php wp_bannerize_pro(); ?>Without arguments, all published and active banners are displayed.
Display a Specific Banner
<?php wp_bannerize_pro(['id' => 42]); ?>Display Banners from a Campaign
<?php wp_bannerize_pro(['campaigns' => 'sidebar-ads']); ?>Display from Multiple Campaigns
<?php wp_bannerize_pro(['campaigns' => 'header-ads,sidebar-ads']); ?>Limit the Number of Banners
<?php wp_bannerize_pro([
'campaigns' => 'sidebar-ads',
'numbers' => 3,
]); ?>Random Banner Rotation
<?php wp_bannerize_pro([
'numbers' => 1,
'orderby' => 'random',
]); ?>This displays a single random banner, changing on each page load.
Sort by Performance
<?php // Top 5 most-clicked banners ?>
<?php wp_bannerize_pro([
'orderby' => 'clicks',
'order' => 'DESC',
'numbers' => 5,
]); ?><?php // Top 3 banners by click-through rate ?>
<?php wp_bannerize_pro([
'orderby' => 'ctr',
'order' => 'DESC',
'numbers' => 3,
]); ?>Horizontal Layout
<?php wp_bannerize_pro([
'campaigns' => 'footer-ads',
'layout' => 'horizontal',
]); ?>Consistent Random Order with rank_seed
<?php wp_bannerize_pro([
'orderby' => 'random',
'rank_seed' => 12345,
]); ?>Using the same rank_seed value produces the same “random” order each time. Different seeds produce different arrangements.
Device-Specific Display
<?php // Show only on mobile ?>
<?php wp_bannerize_pro([
'campaigns' => 'mobile-ads',
'mobile' => true,
]); ?>
<?php // Show only on desktop ?>
<?php wp_bannerize_pro([
'campaigns' => 'desktop-ads',
'desktop' => true,
]); ?>Post Category Filtering
<?php wp_bannerize_pro([
'campaigns' => 'tech-ads',
'post_categories' => 'technology,gadgets',
]); ?>Banners will only display when the current post is in the “technology” or “gadgets” categories.
Using the Return Value
The get_wp_bannerize_pro() function returns the HTML string, which is useful for conditional logic or post-processing:
<?php
$banners = get_wp_bannerize_pro([
'campaigns' => 'sidebar-ads',
'numbers' => 3,
]);
// Only display if there are banners
if (!empty($banners)) {
echo '<div class="my-banner-wrapper">';
echo $banners;
echo '</div>';
}
?>Check for Available Banners
<?php
$banners = get_wp_bannerize_pro([
'campaigns' => 'holiday-sale',
]);
if (!empty($banners)) {
echo '<section class="promotions">';
echo '<h2>Special Offers</h2>';
echo $banners;
echo '</section>';
} else {
// Fallback content when no banners are active
echo '<section class="promotions">';
echo '<p>Check back soon for special offers!</p>';
echo '</section>';
}
?>Theme Integration Examples
In header.php
<header class="site-header">
<div class="header-banner-area">
<?php wp_bannerize_pro([
'campaigns' => 'header-leaderboard',
'numbers' => 1,
'layout' => 'horizontal',
'desktop' => true,
]); ?>
</div>
</header>In sidebar.php
<aside class="sidebar">
<?php wp_bannerize_pro([
'campaigns' => 'sidebar-ads',
'numbers' => 3,
'orderby' => 'random',
]); ?>
</aside>In single.php (After Content)
<article>
<?php the_content(); ?>
<div class="post-footer-banners">
<?php wp_bannerize_pro([
'campaigns' => 'in-content',
'numbers' => 1,
'orderby' => 'random',
'post_categories' => 'news,technology',
]); ?>
</div>
</article>The PHP functions respect all banner settings including scheduling (Date From / Date Expiry), performance limits (Max Impressions / Max Clicks), and per-banner tracking toggles.
Make sure the Bannerize plugin is active before calling these functions in your theme. Wrap the call in a function_exists() check to avoid fatal errors if the plugin is deactivated:
<?php
if (function_exists('wp_bannerize_pro')) {
wp_bannerize_pro(['campaigns' => 'sidebar-ads']);
}
?>