In Article Ads And Single Ads Shortcode Wordpress With WP AMP NINJA Plugin
Adsense Shortcode Wordpress Compatible With WP AMP NINJA Plugin
Call Adsense JavaScript (adsbygoogle.js)
function saotn_loadAdsByGoogleJs() { wp_register_script( 'google-adsense', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', '', '', true ); wp_enqueue_script( 'google-adsense' ); } add_action( 'wp_enqueue_scripts', 'saotn_loadAdsByGoogleJs' );
Create In Article Ads Shortcode
Goto Adsense Dashboard -> My Ads -> Add New -> Choose In Article Ads -> Set with your defined settings -> Get Code from <ins until </script> dont copy script.js above </ins>.//In Article Ads function IAA($atts) { $urlamp = (isset($_SERVER['HTTPS']) ? "https" : "http") . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (strpos($urlamp,'wpamp') !== false) { //echo 'Car exists.'; return '<amp-ad layout="fixed-height" height=100 type="adsense" data-ad-client="ca-pub-7975270895217217" data-ad-slot="7382733759"> </amp-ad>'; } else { return '<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-XXXXXXXXXX" data-ad-slot="XXXXXXXXXX"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>'; } } add_shortcode('ads', 'IAA');Add shortcode [ads] in every post Location.
Replace ad-client and ad-slot with your in article ads client and slot number.
Add Shortcode Responsive Adsense
Goto Adsense.Google.com -> My Ads -> Ad New -> Choose Text And Image Ads -> Choose Responsive Ads -> Get Code from <ins until </script> dont copy script.js above <ins>.//Single Adsense function adsens($atts) { extract(shortcode_atts(array( 'adsid' => h50, 'height' => 250, ), $atts)); $google_code = '<ins id="'.$adsid.'" class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXXXX" data-ad-slot="XXXXXXXXXX" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>'; $ampr = '<amp-ad layout="fixed-height" id="'.$adsid.'" height='.$height.' type="adsense" data-ad-client="ca-pub-XXXXXX" data-ad-slot="XXXXXXXXXX"></amp-ad>'; $urlamp = (isset($_SERVER['HTTPS']) ? "https" : "http") . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if (strpos($urlamp,'wpamp') !== false) { return $ampr; } else { return $google_code; } } add_shortcode('adsense', 'adsens');add shortcode [adsense height="50" id="YOURID"]
Change number 50 to your defined height in pixel (px).
YOURID change with your defined ID (if you have css to styling this ads).
Done. In Article Ads And Single Ads Shortcode Wordpress With WP AMP NINJA Plugin hope be functionally for your adsense.
Comments
Post a Comment
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.