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 */

Subscribe to receive free email updates:

1 Response to "Create Adsense shortcode for WordPress"

  1. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here. php training in chennai

    ReplyDelete

Bila Ada posting yang kurang, atau error atau yang lainnya, silahkan tinggalkan komentar agar artikel/post di perbaiki.
Jangan Lupa Cek Box "Notify Me" agar tahu komentar kamu dibalas oleh saya.

If there are any posts that are missing, or error or anything else, please leave a comment for the article / post to be fixed.
Do not Forget Check Box "Notify Me" to know our comments replied by me.