Display Google Advertise Inside blog post

title-img-post“Google Advertise”
[pmb]
Google Adsense Network is worldwide most popular advertise network. We can display Google advertises to any website’s header area, footer area, sidebar, between posts as well as inside post. Now when it comes to displaying Google advertise inside post, then it becomes a bit tricky process. Let’s learn how to display Google advertise inside the post.

Process of putting Google advertises inside a post

Mostly blogger uses two types of blogging platforms, WordPress or Blogger. Here we will teach for both the platform. We strongly advise you to take a backup of the theme (you can backup your currently active theme from your dashboard option at Template-> Backup and restore). And if you using Word press then use a child theme so if anything goes wrong, you can re-active previous setting theme.                “Google Advertise”

1 How to display Google advertise inside blogger post?

 

Step-1

First of all, you need to go to your Google Adsense account and create a advertise unit. Convert Adsense code into plain text HTML (you will need to “parse” the code before pasting it to Blogger Html section). Now cut across to your blogger dashboard and find the “Template” tab. now you have to open “Edit Html” tab.

Step-2

Now you need to press “Control + F” key. It will appear a search box at right-hand side top of your screen. Now you have to type in “<data:post.body/>” (Note- do not include double inverted commas). When you search for <data:post.body/> in the search box, Make sure that your cursor is inside code area. (see image below)

data-post-body

Step-3

Now replace the <data:post.body/> tag with following codes.

***Code***

<div expr:id='”adsmiddle1″ + data:post.id’></div>

<b:if cond=’data:blog.pageType == “item”‘>

<b:if cond=’data:blog.pageType != &quot;static_page&quot;’>

<div style=”clear:both; margin:10px 0″>

<!– Add here the code of your Google advertise –>

</div>

</b:if>

</b:if>

<div expr:id='”adsmiddle2″ + data:post.id’>

<data:post.body/>

</div>

<script type=”text/javascript”>

var obj0=document.getElementById(“adsmiddle1<data:post.id/>”);

var obj1=document.getElementById(“adsmiddle2<data:post.id/>”);

var s=obj1.innerHTML;

var r=s.search(/\x3C!– adsense –\x3E/igm);

if(r>0) {obj0.innerHTML=s.substr(0,r);obj1.innerHTML=s.substr(r+16);}

</script>

***End Code***

Step-4

Now put the converted “parsed” code inside above at “<!– Add here the code of your Google advertise –>”. (Note- do not include double inverted comas) and at last save the template.

Step-5

Whenever you create a new post and you wish to add Google advertise inside that post you just have to write one short tag code. “<!–AdSense–>”  see image below to get clear idea of it.

short-code-lable

Note- remember that you have to paste <!–AdSense–> code at post’s “HTML” form. If you paste <!–AdSense–> code in plan text area of your new post, then it won’t work. so always use it in HTML.

Example-

<div> this is the best post ever I visited</div>

<!–AdSense–>

<div>I learn a lot from this post</div>

<!–AdSense–>

<div>thanks very much for posting such informative post</div>      

Note-

If you wish to display your Adsense code align left then you don’t need to do anything, but if you need it to appear in the center then you can simply use below style.

<Center> <!–paste your Google Adsense code here–></center>

More- again I insist that you must take a backup of your theme before making any changes to it. Do not paste more than 3 Google ads at one page. After pasting codes wait for 15 minutes, it may take 10 to 15 minutes to appear advertises.

2 How to Display Google Advertises Inside WordPress Post?

If you are using WordPress software platform for blogging then you can search for official Google AdSense plug-in. Just install the plug-in and manage your ads inside your post. But if you want to display Google advertises inside your post without using a plug-in, and then follow the steps given above.

Step-1

First of all, go to your ad-sense account and create your desired ad unit. Now cut across to your WordPress dashboard. Now go to “your theme editor” (normally “editor” option lies under theme tab). The whole bunch of codes will appear on your screen.

Step-2

Now take a look at right side of your screen, from that list find “function.php” tab. just open that tab link. Now again some codes will appear of function.php. on your screen. You need to add one simple function to that function.php code list. See it on step-3.

Step-3

Just paste this easy function code at the end of your function.php

***Code***Example-1

function MyAdSenseCodeFunction(){

return ‘  <put your Google Adsense Code Here>

}

add_shortcode(‘abc’,’MyAdSenseCodeFunction’);

***End Code***

 

===that’s it========now see below another example with same function to learn it clearly===

***Code*** Example-2

function MyAdSenseCodeFunction(){

return ‘<script async src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script>

<!– Link-ads –>

<ins class=”adsbygoogle”

     style=”display:block”

     data-ad-client=”ca-pub-7152265774548540″

     data-ad-slot=”6586524215″

     data-ad-format=”link”></ins>

<script>

(adsbygoogle = window.adsbygoogle || []).push({});

</script>’;

}

 

add_shortcode(‘abc’,’MyAdSenseCodeFunction’);

 

***End Code***

Step-4

Now after pasting above mention code to your function.php you can replace Google Adsense Code with your ad unit code. As you can see I already did it with the second example.

Step-5

“Abc” is your short code. Whenever you want to place an ad inside your blog post, you just need to go to your created post and press the “HTML” out of (“HTML” “text”)tabs. You can choose your desired place Inside “HTML” code area and just wrote short code “ABC”(imp note- use your shortcode in square bracket only like this [abc]). And save the changes.

Note- your ad code will show up within fifteen minutes or within half an hour. If you want to set the alignment of your advertise then you can use a <center></center> command. If you wish to display your Google advertise at left side then you don’t need to do anything, it will display at left align by default.            “Google Advertise”

 

 

 
[pmb]

Now let me explain the whole code details.

  • MyAdSenseCodeFunction is fiction name, you can give any name in place of that name.
  • When you paste your own Google Ad unit inside this function make sure you remove <put your Google Adsense Code Here> with this <> signs.
  • You suppose to paste this function + your Google Adsense code at the end of your theme’s Function.php but make sure that if you have ?> this PHP end sign, at the end of your function.php. then paste your new created function before this ?> PHP closing tag. Otherwise, it will show error.
  • Always make changes after creating a child theme. But if accidently you messed up your theme, then don’t get panic. Just follow the below given steps.

 

My own experience-

Some days ago I made some changes to my ribbon theme. Means I just added above Google Adsense advertise inside the function And then tried to save the settings. But unfortunately, I forget a bracket “}” close inside that function. My whole website hanged. Backhand and display website both started showing error infect it was broken down. Then I followed this steps. Read it… and learn the important troubleshoot…

Step-1

I went to my hosting provider’s control panel area, and then I have searched public_html folder. Remember this folder contains whole files which are online at your website. I just searched for my theme folder. Inside my theme folder, I found function.php. I knew that that function.php file was the culprit. I just copied that file means I downloaded that file.

Step-2

Then after I opened that downloaded function.php file and copied whole codes. I have searched online PHP error finding websites at Google search. Instantly I found that “}” bracket was missing. I repaired it and replaced it with broken function.php file.

Step-3

I just saved the settings  And boom…. My website was on air same as it was before editing function.php

Conclusion- this is how I recovered from that simple but critical error. I don’t advice to play with fire like I played in the past. Maybe I was lucky enough to recover from that horror situation. Therefore, I would advise you to use a child theme so you can safely experiment with it.

Thanks for reading the full post. Don’t forget to leave a comment if you liked the post, and also you can add some inputs if you have extra knowledge about “setting up google Adsense advertises inside post” topic. – stay connected.

READ ALSO-

What Is Website Bounce Rate – How it effects Your Website Traffic 

 

Leave a Reply

Your email address will not be published. Required fields are marked *