Creating Inline Tags for Google Ad Manager

We provide the code snippets and content on this page without any guarantee or support. In most cases, these pages are created on requests or based on individual solutions sent to us by other users. After it was published, we are only reviewing the code and content when we are made aware of an issue. Please let us know if you find one.

Please only use the codes if you understand them and know how to add custom code to your WordPress site.

By default, Google Ad Manager comes with head and body codes. Matching them across different pages is often a challenge, as you can see in How to insert Google Ad Manager ads into WordPress.

Our Google Ad Manager WordPress plugin manages that automatically. We recommend that you use the plugin instead of the manual code below.

For anyone who needs to create GAM tags manually, using Inline Tags is a simple solution to not having to worry about matching head and body tags. Inline Tags combine head and body codes into one snippet that is placed directly where the ad should show up in the body.

Inline tags come with the limitation for features that rely on the Single Request Architecture, like roadblocks.

How to create Google Ad Manager Inline Tags

1. Get ad unit codes

Open your Google Ad Manager account and get the head and body codes for a given ad unit.

The highlighted code is the one you would also need in your inline tags.

Example for a head code:

<script async src=""></script> <script> window.googletag = window.googletag || {cmd: []}; googletag.cmd.push(function() { googletag.defineSlot('/1234567890/medium-rectangle', [300, 250], 'div-gpt-ad-987654321-0').addService(googletag.pubads()); googletag.enableServices(); }); </script>
Code language: HTML, XML (xml)

Example for a body code:

<!-- /1234567890/medium-rectangle --> <div id='div-gpt-ad-987654321-0' style='min-width: 300px; min-height: 250px;'> <script> googletag.cmd.push(function() { googletag.display('div-gpt-ad-987654321-0'); }); </script> </div>
Code language: HTML, XML (xml)

2. Combine head and body code

Take the bold parts of the above codes and combine them into one. You can copy the inline code from below as a whole and adjust the metrics.

The highlighted line in the inline tags code is not exactly part of the original ad unit tags. You can get the values for it from the head tag above.

<script async="async" src=""></script> <script> window.googletag = window.googletag || {cmd: []}; </script> <div id='div-gpt-ad-987654321-0'> <script> googletag.cmd.push(function() { googletag.pubads().display('/1234567890/medium-rectangle', [300, 250], 'div-gpt-ad-987654321-0'); }); </script> </div>
Code language: HTML, XML (xml)

3. Displaying the ad unit

In Advanced Ads, create a new ad with the Plain Text type and include your inline ad code. You can now use the shortcode or placement to display the ads.

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.