Create Adsense shortcode for WordPress

  1. Go to Your Dashboard WordPress
  2. Click menu -> Appearance
  3. Click editor -> choose functions.php
  4. Add below code inside <?php
/*
* enqueue adsbygoogle.js in the footer &
* create a WordPress shortcode with your Google AdSense code
* follow me on Twitter: @DimasSkynetCybe
/

function loadAdsenseJS() {
wp_register_script( ‘google-adsense’, ‘//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js’, ‘’, ‘’, true );
wp_enqueue_script( ‘google-adsense’ );
}
add_action( ‘wp_enqueue_scripts’, ‘loadAdsenseJS’ );

function AdSense() {
$output = ‘<ins class=“adsbygoogle”
style=“background-color: transparent;
text-decoration: none;
display:inline-block;
width:336px;
height:280px”
data-ad-client=“ca-pub-xxYourUniqueIdxx”
data-ad-slot=“xxUniqueIdSlotxx”></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>’;

return $output;
}
add_shortcode( ‘adsense’, ‘AdSense’ );


/

* Usage: add [adsense] in your WordPress posts
* where you want your ad to appear
*/