Hide & Show Adsense Responsive ads Without Violating TOS in Different Positions

How to Reposition or Hide/Show Adsense Responsive Ads in Different Positions in Responsive to Screen Resolution
Hiding adsense ads are concidered as a policy violation by Google, Google limits maximum 3 display advertising per a page, so properly displaying ads responsive to screen size is an important factor.

Why reposition?
Because of sidebars or responsive elements
Usually in responsive designs on mobile view, sidebars are pushed to the bottom of content after the article, in that case displaying the ad displayed on sidebars in above/below/within article is a better idea like the following image

Add the above Javascript code to head section of HTML once, like the asynchronous adcodes writeADS function will be called when its required, When an adsense sync javascript is called it will definitely display an advertisement even if you don’t define a adslot or adclient ids; to skip this show_ads.js must be loaded conditionally, this is where wirteADS function comes in handy

Here is an example of Conditionally showing Synchronous adsense ads in responsive to screen width, Javascript checks if the screen width is Greaterthan or Equal to 728 if the condtions match it will show a Leaderboard ad (728×90) writeADS() function is called at the end if the condtions don’t match writeADS() function will not be executed, that is how the code below prevents your adsense codes violating adsense

When using Synchronous adcodes, ad slots must be replaced for every ad sizes that you want to use but in responsive ads same ad slot can be used and it can be customized to show in different locations with CSS Media queries
To understand it perfectly let assume you are showing a 728×90 ad at the bottom of your articles for desktops but if you want to show the same ad before the article for Mobile devices this trick comes in handy

This Javascript goes in bottom of article, which shows 728×90 ad for screen widths greater or equal to 800px screen widths

You don’t have to change the ad slot here but the css class has been changed note that, that is an important factor when using same ad slot but displaying ad on different positions in responsive to screen width

Hiding Asnchronous non responsive adcode in compliance to adsense TOS will be updated in this same article soon