Skip to main content

Manual display with shortcodes, template tags, and blocks

Ads and Groups can be manually placed on your site using three methods: shortcodes, PHP functions (template tags), and blocks.

Shortcodes

The shortcode for embedding an ad is adcmdr_ad and the shortcode for a group is adcmdr_group. Using either shortcode requires you to specify the ID of the ad or group. The ID can be found in the URL, or by simply looking at the shortcode preview while editing an ad or group.

Shortcode and template tag screenshot
Shortcode and template tag screenshot

Paste your shortcode into a page, post, custom post type, or anywhere else shortcodes will execute. WordPress also offers a shortcode block to make adding shortcodes to your content easier.

Shortcode parameters

As mentioned above, the “id” parameter is required for both ads and groups. Both shortcodes also accept two additional parameters:

  • disable_wrappers – Defaults to false; Setting to true will disable any wrappers around the ad or group.
  • force_noajax – Defaults to false; Setting to true will force the ad or group to load without considering whether an Ajax container should load instead. This essentially forces the ad or group to load with server-side rendering.

PHP functions (template tags)

If you prefer to embed your ads in your theme or a plugin, you can do so with the PHP functions adcmdr_the_ad and adcmdr_the_group — and their related functions adcmdr_get_ad and adcmdr_get_group.

These functions work similarly to the above shortcodes. The first parameter is an ID, and the second parameter is an array of arguments. In addition to the arguments accepted by the shortcodes, these functions also accept the argument force_nocheck. When set to true, this argument will force consent checking to be skipped.

<?php adcmdr_the_ad(100, array( 'disable_wrappers' => false, 'force_noajax' => false, 'force_nocheck' => false )); ?>

The template tags with the word “the” will display the ad or group to the page. Alternatively, you can use adcmdr_get_ad and adcmdr_get_group if you prefer to return the ad or group without displaying it on the page.

<?php 
$ad = adcmdr_get_ad(100); 
// do something here with $ad
echo $ad;
?>

Blocks

Ad Commander has a single block for displaying ads or groups. This block has no options beyond selecting the ad or group from a dropdown. Simply select your ad or group and it will display where you place the block.

Ad or group WordPress block

Automatic placements

Ads and groups can also be placed automatically using Automatic Placements. Learn more in the automatic placement documentation.