Total Pageviews

Sunday 14 October 2018

Google Adsense Code ,Where to place the ad code in your HTML (Auto ads)

Code implementation guide

Where to place the ad code in your HTML (Auto ads)



After you've generated the ad code for your Auto ads, you'll need to place the code once on each page that you want to show the ads. You should place your ad code in the <head> tag (or at the top of the body) of your page.


The following examples show you where to place the code:

Example HTML page before the Auto ad code has been added

<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
</body>
</html>

Example HTML page with the Auto ad code added in the <head>tag

<html>
<head>
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-123456789",
enable_page_level_ads: true
});
</script>

This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
</body>
</html>
Note that this is sample code only, please don't use it in your own website code.

Example HTML page with the Auto ad code added at the top of the body

If you don't have access to the <head> tags of your page, then you can place the ad code at the top of the body instead:
<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-123456789",
enable_page_level_ads: true
});
</script>

This is the body of your page.
</body>
</html>


Code implementation guide

Where to paste the ad code in your HTML (ad units)



It's important that you paste your ad unit code between the <body> and </body> tags of your page. If you paste the ad code outside the <body> tags it will prevent your ads from appearing correctly.


Example HTML page before the ad unit code has been added

<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
</body>
</html>

Example HTML page with the ad unit code added in the body

<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Homepage Leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

</body>
</html>

Note that this is sample code only, so please don't use it in your own site's code.

Positioning the ads on your site with HTML

Just like the other elements of your site (images, paragraphs, etc.), you can change the position of your Google ads by using HTML tags (<div><table>, etc.). For example, if you surround your ad code with the HTML tags <div align="center"> and </div>, your ads will appear in the centre of your page.
<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<div align="center">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Homepage Leaderboard -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1234567890123456"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</body>
</html>


How to paste the ad code in your page


Once you've copied the ad code from your AdSense account, the next step is to paste it in your page’s HTML source code. How you go about this will depend on the tools that you use to edit your site.

Before adding the ad code to your page, please make sure that your page complies with the AdSense programme policies. If your page doesn't comply with these policies, we reserve the right to disable ad serving to your site and/or disable your AdSense account at any time.


HTML editors

Many publishers use a design-enhanced HTML editor like Macromedia Dreamweaver (also know as WYSIWYG or "what you see is what you get" software). To ensure your ads work properly, make sure that you paste the ad code into the HTML source code of your page using the editor's HTML view or HTML insert function. You might see errors if you paste your ad code into a WYSIWYG view such as a "Design" view. Once you've pasted your code, check for any additional tags inserted by the software or changes in the line breaks, as they might cause your ads not to show correctly.
If you can't find the HTML source code of your page in your editor, please visit the help centre or support group for your HTML editing software.

Content management systems (CMS)

If you're using a content management system, check below to see if your CMS has AdSense built in or if it supports a plugin that can help you to implement your AdSense ad code.

Sites with AdSense built in

CMS software with unofficial plugins

The following content management systems (CMS) use third-party plugins to insert AdSense ads on the pages generated by the system. Google does not endorse or support these plugins. However, you can use these plugins as long as the ad code displayed on your page remains unchanged and isn't altered by the plugin in any way.
WordPress user? Get help with adding AdSense code.
If you need assistance with a plugin, then please visit the official support forum of your service or the developer of the plugin. Please note that Google is not responsible for malicious third-party plugins.
If you have trouble implementing AdSense with a specific content management system, we recommend searching for the name of the CMS (e.g. Drupal, WordPress, etc.) and "AdSense implementation". You can also ask in the forum if other publishers have mastered similar problems, or contact your programme provider directly.






Note that this is sample code only, please don't use it in your own website code.

No comments:

Post a Comment