Archived topic
Hello Sir My Code Right or Wrong For amp or non amp ads
1 reply · Started by Sampat Jangir on January 26, 2021
function wpb_shortcode() {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
// Advertisement code pasted inside a variable
$string .= '<amp-ad width="100vw" height="320"
type="adsense"
data-ad-client="ca-pub-1279876048707018"
data-ad-slot="3396848599"
data-auto-format="rspv"
data-full-width="">
</amp-ad>';
return $string;
}
else {// Advertisement code pasted inside a variable
$string .= '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- post 4 -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1279876048707018"
data-ad-slot="3396848599"
data-ad-format="auto"
data-full-width-responsive="true">
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
return $string;
}
} // Register shortcode
add_shortcode('ad', 'wpb_shortcode');
Hi,
I'm not exactly sure if the wrong syntaxes for delimiters ‘,’,” and > were because it wasn't formatted as code when you pasted it on the forums but other than that, the code seems to make sense.
I believe it's suppose to look like this?
function wpb_shortcode() {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
// Advertisement code pasted inside a variable
$string .= '<amp-ad width="100vw" height="320"
type="adsense"
data-ad-client="ca-pub-1279876048707018"
data-ad-slot="3396848599"
data-auto-format="rspv"
data-full-width="">
</amp-ad>';
return $string;
}
else {// Advertisement code pasted inside a variable
$string .= '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!– post 4 –>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1279876048707018"
data-ad-slot="3396848599"
data-ad-format="auto"
data-full-width-responsive="true">
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
return $string;
}
} // Register shortcode
add_shortcode('ad', 'wpb_shortcode');
It should work.