Advanced Ads Shortcodes

Below, you’ll find a detailed guide on how to add the Advanced Ads – Ad Manager & AdSense Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Advanced Ads – Ad Manager & AdSense Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Advanced Ads – Ad Manager & AdSense Plugin and the shortcodes it provides:

Plugin Icon
Advanced Ads – Ad Manager & AdSense

"Advanced Ads – Ad Manager & AdSense is a comprehensive plugin designed to optimize your website's ad space. It simplifies AdSense integration and ad management for superior results."

★★★★☆ (1380) Active Installs: 100000+ Tested with: 6.3.2 PHP Version: 7.2
Included Shortcodes:
  • [the_ad]
  • [the_ad_group]
  • [the_ad_placement]

Advanced Ads – Ad Manager & AdSense [the_ad] Shortcode

The Advanced Ads plugin shortcode, ‘the_ad’, is designed to display ads on your website. This shortcode takes in attributes (atts), which can be an array or an ID. If ‘inline’ is set or found in the array, an inline wrapper element is created. The attributes are then prepared and the ad associated with the given ID is returned and displayed.

Shortcode: [the_ad]

Parameters

Here is a list of all possible the_ad shortcode parameters and attributes:

  • id – The unique identifier for the ad to be displayed
  • inline – Sets the ad to be displayed inline within the content

Examples and Usage

Basic example – Displaying an ad using its unique ID

[the_ad id=1 /]

Using the ‘the_ad’ shortcode, we can display an ad by referencing its unique ID. In this example, the ad with an ID of 1 will be displayed.

Advanced examples

Displaying an ad inline with other content

[the_ad id=1 inline /]

In this advanced example, we’re using the ‘inline’ attribute to display the ad inline with other content. The ad with an ID of 1 will be displayed inline.

Displaying an ad with custom attributes

[the_ad id=1 inline custom_attr="value" /]

Here, we’re using a custom attribute along with the ‘id’ and ‘inline’ attributes. The ‘custom_attr’ attribute can be replaced with any valid attribute for the ‘the_ad’ shortcode. The ad with an ID of 1 will be displayed inline and the custom attribute will be applied.

PHP Function Code

In case you have difficulties debugging what causing issues with [the_ad] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'the_ad', [ $this, 'shortcode_display_ad' ] );

Shortcode PHP function:

function shortcode_display_ad( $atts ) {
		$atts = is_array( $atts ) ? $atts : [];
		$id   = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
		// check if there is an inline attribute with or without value.
		if ( isset( $atts['inline'] ) || in_array( 'inline', $atts, true ) ) {
			$atts['inline_wrapper_element'] = true;
		}
		$atts = $this->prepare_shortcode_atts( $atts );

		// use the public available function here.
		return get_ad( $id, $atts );
	}

Code file location:

advanced-ads/advanced-ads/classes/plugin.php

Advanced Ads – Ad Manager & AdSense [the_ad_group] Shortcode

The Advanced-Ads plugin shortcode, ‘the_ad_group’, is designed to display a specific ad group. The shortcode function, ‘shortcode_display_ad_group’, accepts attributes to determine the ad group to be displayed. The ‘id’ attribute identifies the specific ad group. The ‘prepare_shortcode_atts’ function prepares these attributes. It then calls ‘get_ad_group’ function to fetch and display the ad group.

Shortcode: [the_ad_group]

Parameters

Here is a list of all possible the_ad_group shortcode parameters and attributes:

  • id – The unique identifier for the specific ad group.
  • atts – An array used to customize the display of the ad group.

Examples and Usage

Basic example – Displaying an ad group by referencing its ID.

[the_ad_group id=1 /]

Advanced examples

Displaying an ad group by referencing its ID and setting additional parameters. In this example, we’re setting the ‘align’ parameter to ‘center’ and ‘width’ parameter to ‘50%’. This will center the ad group and set its width to 50% of its parent container.

[the_ad_group id=1 align="center" width="50%" /]

Using the shortcode to display multiple ad groups by referencing their IDs. The ad groups will be displayed in the order they are listed in the shortcode.

[the_ad_group id="1,2,3" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [the_ad_group] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'the_ad_group', [ $this, 'shortcode_display_ad_group' ] );

Shortcode PHP function:

function shortcode_display_ad_group( $atts ) {
		$atts = is_array( $atts ) ? $atts : [];
		$id   = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
		$atts = $this->prepare_shortcode_atts( $atts );

		// use the public available function here.
		return get_ad_group( $id, $atts );
	}

Code file location:

advanced-ads/advanced-ads/classes/plugin.php

Advanced Ads – Ad Manager & AdSense [the_ad_placement] Shortcode

The Advanced Ads plugin shortcode, ‘the_ad_placement’, is designed to display ad placements on your WordPress site. It accepts attributes, specifically ‘id’, to specify the ad placement. The PHP function ‘shortcode_display_ad_placement’ processes these attributes. It uses the ‘get_ad_placement’ function to return and display the ad placement associated with the given ‘id’.

Shortcode: [the_ad_placement]

Parameters

Here is a list of all possible the_ad_placement shortcode parameters and attributes:

  • id – Unique identifier for the ad placement
  • atts – Array to modify the default settings of the ad placement

Examples and Usage

Basic example – A simple usage of the shortcode to display an ad placement by referencing its ID.

[the_ad_placement id="123" /]

Advanced examples

Display an ad placement with additional attributes. In this example, we are using ‘size’ and ‘format’ as additional parameters. The ad placement will first try to load by ID, but if not found, it will try to load by size and format.

[the_ad_placement id="123" size="large" format="banner" /]

Another advanced example would be to display an ad placement with ‘align’ and ‘class’ parameters. The ad placement will first try to load by ID, but if not found, it will try to load by align and class.

[the_ad_placement id="123" align="center" class="my-custom-class" /]

These examples show the flexibility and power of shortcodes in WordPress. By using various parameters, you can control how and where your ads are displayed on the site.

PHP Function Code

In case you have difficulties debugging what causing issues with [the_ad_placement] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'the_ad_placement', [ $this, 'shortcode_display_ad_placement' ] );

Shortcode PHP function:

function shortcode_display_ad_placement( $atts ) {
		$atts = is_array( $atts ) ? $atts : [];
		$id   = isset( $atts['id'] ) ? (string) $atts['id'] : '';
		$atts = $this->prepare_shortcode_atts( $atts );

		// use the public available function here.
		return get_ad_placement( $id, $atts );
	}

Code file location:

advanced-ads/advanced-ads/classes/plugin.php

Conclusion

Now that you’ve learned how to embed the Advanced Ads – Ad Manager & AdSense Plugin shortcodes, 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *