Below, you’ll find a detailed guide on how to add the Universal Google Adsense and Ads manager Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Universal Google Adsense and Ads manager Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Universal Google Adsense and Ads manager Plugin and the shortcodes it provides:
"Universal Google Adsense and Ads Manager is a versatile plugin that simplifies the process of managing and implementing Google Adsense ads on your WordPress site."
- []
Universal Google Adsense and Ads manager [ugaam_ad] Shortcode
The Universal Google AdSense and Ads Manager (UGAAM) shortcode is designed to create ad sections. The shortcode is: [ugaam_ad]. It enables users to add custom CSS classes to the ad wrapper.
The ad content is placed within the wrapper and can be divided into multiple sections. If a class is specified, the content is split at each ” marker. The shortcode then outputs a structured div container with the ad content.
Shortcode: [ugaam_ad]
Parameters
Here is a list of all possible null shortcode parameters and attributes:
class
– adds custom CSS classes to the ad wrappercontent
– adds the ad content inside the ad wrapper
Examples and Usage
Basic example – Utilizing the ‘ugaam_ad’ shortcode to display ads with default settings.
[ugaam_ad /]
Advanced examples
The ‘ugaam_ad’ shortcode with a custom CSS class. The class attribute allows you to style the ad wrapper with your own CSS.
[ugaam_ad class="my-custom-class" /]
Using the shortcode to display multiple ads with different CSS classes. This gives you the flexibility to style each ad differently based on its class.
[ugaam_ad class="ad-class-1" /]
[ugaam_ad class="ad-class-2" /]
[ugaam_ad class="ad-class-3" /]
Embedding content within the ‘ugaam_ad’ shortcode. The content placed between the opening and closing tags of the shortcode will be treated as an ad content.
[ugaam_ad class="ad-class-1"]Your ad content goes here.[/ugaam_ad]
Using the shortcode to display ad content with a comment tag. The content within the comment tag will be treated as an ad content.
[ugaam_ad class="ad-class-1"]Your ad content goes here.[/ugaam_ad]
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'ugaam_ad', array( $this, 'create_shortcode' ) );
Shortcode PHP function:
function create_shortcode( $attrs, $content ) {
$css_class = !empty( $attrs['class'] ) ? $attrs['class'] : '';
$contents = '';
if( ! empty( $css_class ) ) {
$css_classes = !empty( $css_class ) ? explode( ' ', $css_class ) : '';
$contents = ( explode( '<!-- ad -->', $content ) ) ? explode( '<!-- ad -->', $content ) : $content;
}
ob_start();
?>
<div class="ugaam-ad-wrapper-outer <?php if( !empty( $css_class ) ) { echo esc_attr( $css_class ); } ?>">
<div class="ugaam-ad-wrapper">
<div class="ugaam-ad-wrapper-inner">
<?php
if( is_array( $contents ) ) {
foreach( $contents as $ad_content ) {
?>
<p class="ugaam-ad-content">
<?php echo do_shortcode( $ad_content ); ?>
</p>
<?php
}
} else {
?>
<p class="ugaam-ad-content">
<?php echo do_shortcode( $content ); ?>
</p>
<?php
}
?>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
Code file location:
universal-google-adsense-and-ads-manager/universal-google-adsense-and-ads-manager/includes/functions/shortcodes.php
Conclusion
Now that you’ve learned how to embed the Universal Google Adsense and Ads manager Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply