AMP ads for all WordPress sites (AMP and Non-AMP).
This plugin generates <amp-ad> code for your ads with breakpoints for responsive display of ad with Single Request Architecture (SRA).
Works without AMP plugin as well for Non-AMP pages.
Contributors: rtCamp, Vishal Dodiya, Pradeep Sonawane, Sagar Nasit
Tags: amp, mobile
Requires at least: 4.9
Tested up to: 5.1
License: GPLv2 or later
Requires PHP: 5.4+
- Set network/publisher id in the plugin settings.
Dashboard > AMP AdManager - Select
Load AMP Resources for Non-AMP siteto loadamp-runtimeandamp-boilerplatecss.
Pass different ad sizes as attributes for mobile, tablet, and desktop ads. The plugin uses the width of the specified size to determine which device ad should be displayed.
- Width equal to or more than
728will be considered as desktop sizes eg.980x250,970x90. - Width between
300and600will be considered as a tablet sizes eg.320x50,300x100,468x60. - Width less than
300will be considered as mobile sizes eg.250x50,150x150.
In case of unusual sizes for desktop, tablet and mobile specific device size attribute, like
mobile-sizesfor mobile.tablet-sizesfor tablet.desktop-sizesfor desktop.
[ampad ad-unit="<ad-unit-name>"
sizes="320x50,300x100,300x50,468x60,980x250,970x90"
custom-targeting="key1:value1, key2:value2" ad-refresh="30"]
[ampad ad-unit="<ad-unit-name>"
desktop-sizes="320x100,300x100"
tablet-sizes="468x60,300x100"
mobile-sizes="300x100,320x50"
custom-targeting="key1:value1, key2:value2"]
[ampad ad-unit="<ad-unit-name>"
sizes="300x100,320x50,910x150"
desktop-sizes="320x100,300x100"
custom-targeting="key1:value1, key2:value2"]
sizes attribute and custom sizes attrubutes can be used simutanously where custom sizes attributes overtake sizes attribute.
In above example 300x100 and 320x50 are for tablet and 910x150 is for desktop as per caculation on width. But since we defined desktop-sizes as well, it will override previous desktop size of 910x150 and new desktop sizes will be 320x100 and 300x100. Other sizes for mobile and tablet will remain intact as we have not specified custom sizes for mobile and tablet.
$attr = [
'ad-unit' => '<ad-unit-name>',
'sizes' => '320x50,300x100,300x50,468x60,980x250,970x90',
'layout' => 'responsive',
'custom-targeting' => 'key1:value1, key2:value2'
];
AMP_AdManager\AMP_AdManager::get_ads( $attr, true );$attr = [
'ad-unit' => '<ad-unit-name>',
'mobile-sizes' => '320x50,300x100',
'tablet-sizes' => '300x50,468x60',
'dekstop-sizes' => '980x250,970x90',
'layout' => 'responsive',
'custom-targeting' => 'key1:value1, key2:value2'
];
AMP_AdManager\AMP_AdManager::get_ads( $attr, true );-
$attr(Array) These are passed directly to theget_adsvia template tag shown above or via shortcode.Default value: array
[ 'network-id' => '', 'ad-unit' => '', 'mobile-sizes' => '320x50,300x100', // consider for mobile 'tablet-sizes' => '300x50,468x60', // consider for tablet 'dekstop-sizes' => '980x250,970x90', // consider for desktop 'sizes' => '320x50,300x50,468x60,980x250,970x90', 'layout' => 'fixed', 'custom-targeting' => '', 'ad-refresh' => 30, // refresh ad every 30 seconf. ] -
$echo(Boolean) Outputs amp-ad tag if true, returns amp-ad html as value otherwise.
Single Request Architecture(SRA)is enabled by default andAd refreshis disabled in default ad attributes. But SRA will not work if ad refresh is enabled.
| Targeting Variable | Description |
|---|---|
| author | - post author username (string - lowercase) |
| contentType | - type of content e.g homepage, listingpage, post, page, cpt-name (string - lowercase) |
| authorPage | - archive author page name (string - lowercase) |
| categoryPage | - archive category page name (string - lowercase) |
| tagPage | - archive tag page name (string - lowercase) |
| postCategories | - post categories list (array) ["cat1", "cat2"] (all lowercase - slugs) |
| postTags | - post tags list (array) ["tag1", "tag2"] (all lowercase - slugs) |
| postName | - post name slug (string - lowercase) |
| postId | - post id (numeric) |
- Create new branch from 'master'.
- Name it appropriately, i.e.,
feature/GH-<issue-number>-<name>,<context>/GH-<issue-number>-<what_it_is>. - Create PR against
master. - Request review for your changes and get approvals.
- Tablet ads support default sizes between 300px to 600px of width.
- Add missing single page targeting variables.
- Fix SRA tag loading on both AMP and Non-AMP pages.
- Add ad refresh support.
- Add Single Request Architecture (SRA) support.
- Add custom sizes attributes for shortcode.
- Add single function to get output of mobile, tablet, desktop ads.
- Add additional attribute to specify custom or unusual ad sizes.
- PHPCS fixes.
- Doc changes.
- Add
postNameandpostIdtargeting variables - Rename single post targeting variables -
postCategories,postTags
- Add network id support in shortcode.
- Fix shortcode attributes function.
- Add support for user defined targeting with custom-targeting attribute in [ampad].
- Type casting for Domain variable.
- Add layout attribute in shortcode for layout support.
- Basic plugin with ampad shortcode.
