Ads by WPQuads Shortcodes

Below, you’ll find a detailed guide on how to add the Ads by WPQuads 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 Ads by WPQuads Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Ads by WPQuads Plugin and the shortcodes it provides:

Plugin Icon
Ads by WPQuads – Adsense Ads, Banner Ads, Popup Ads

"Ads by WPQuads is a versatile plugin for managing Adsense Ads, Banner Ads, Popup Ads on your WordPress site. Make ad management convenient with quick-adsense-reloaded."

★★★★☆ (1079) Active Installs: 40000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [quads_ad]
  • [quads_ad]
  • [adsforwp]
  • []
  • [quadsvi]

Ads by WPQuads [quads_ad] Shortcode

The Quick Adsense Reloaded shortcode, ‘quads_ad’, is a simple function that removes unused shortcodes. It ensures your site remains clean and efficient.

Shortcode: [quads_ad]

Examples and Usage

Basic example – The following shortcode example represents the basic usage of ‘quads_ad’ shortcode. The shortcode doesn’t require any parameters or attributes as per the function definition.

[quads_ad]

PHP Function Code

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

Shortcode line:

add_shortcode( 'quads_ad', 'wpquads_remove_unsed_shortcode', 1);

Shortcode PHP function:

function wpquads_remove_unsed_shortcode( $atts ) {
		return '';
	}

Code file location:

quick-adsense-reloaded/quick-adsense-reloaded/includes/mu-plugin/wpquads_remove_shortcode.php

Ads by WPQuads [quads_ad] Shortcode

The Quick Adsense Reloaded (quads_ad) shortcode is used to display advertisements on your WordPress site. It allows you to specify the ad’s ID, alignment, and margin for precise placement. The shortcode first checks if ad display conditions are met. If not, it returns without displaying the ad. It also checks for device-specific ad settings. The ad’s alignment and margin are then determined. Shortcode: [quads_ad] Finally, the shortcode generates the HTML code to display the ad, with the style applied according to the previously determined alignment and margin. This ensures that your ad is displayed exactly as you want it. Shortcode: [quads_ad]

Shortcode: [quads_ad]

Parameters

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

  • id – Specifies the unique identifier of the ad.

Examples and Usage

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

[quads_ad id=1 /]

For more advanced usage, you can utilize several parameters or attributes in the shortcode. However, the ‘id’ attribute is the most critical one as it specifies the ad block to be displayed.

Advanced examples – Displaying multiple ads by referencing their IDs.

[quads_ad id=1 /]
[quads_ad id=2 /]
[quads_ad id=3 /]

In the above example, three different ad blocks will be displayed on the page. Each ad block is referenced by its unique ID. The order of the ads on the page will be the same as the order of the IDs in the shortcode.

Please note that the actual number of ads displayed may be less than the number of IDs specified in the shortcode, depending on the settings of the Quick AdSense Reloaded plugin and the ad blocks themselves. For example, if an ad block is set to not display on certain devices or screen sizes, it will not be shown even if its ID is included in the shortcode.

Remember to replace ‘1’, ‘2’, and ‘3’ with the actual IDs of your ad blocks.

PHP Function Code

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

Shortcode line:

add_shortcode( 'quads_ad', 'quads_shortcode_display_ad', 1); // Important use a very early priority to be able to count total ads accurate

Shortcode PHP function:

function quads_shortcode_display_ad( $atts ) {
    global $quads_options,$quads_shortcode_ids,$quads_mode;

    // Display Condition is false and ignoreShortcodeCond is empty or not true
    if( !apply_filters('quads_show_ads',quads_ad_is_allowed()) && !isset($quads_options['ignoreShortcodeCond']) )
        return;


    //return quads_check_meta_setting('NoAds');
    if( quads_check_meta_setting( 'NoAds' ) === '1' ){
        return;
    }

    // The ad id
    $id = isset( $atts['id'] ) ? ( int ) $atts['id'] : 0;
    $ad_id = isset($quads_options['ads']['ad'.$id.'']) && $quads_options['ads']['ad'.$id.'']!==NULL ? (isset($quads_options['ads']['ad'.$id.'']['ad_id'])?$quads_options['ads']['ad'.$id.'']['ad_id']:NULL ): NULL ;

    if(isset($quads_mode) && $quads_mode == 'old'){
        if(isset($quads_options['ads']['ad'.$id]['phone']) || isset($quads_options['ads']['ad'.$id]['tablet_landscape']) || isset($quads_options['ads']['ad'.$id]['desktop'])){
            $get_device = function_exists('quads_check_my_device') ? quads_check_my_device() : '';
            if(isset($quads_options['ads']['ad'.$id][$get_device]) && $quads_options['ads']['ad'.$id][$get_device] == 1){
                return;
            }
        }
    }

    $arr = array(
        'float:left;margin:%1$dpx %1$dpx %1$dpx 0;',
        'float:none;margin:%1$dpx 0 %1$dpx 0;text-align:center;',
        'float:right;margin:%1$dpx 0 %1$dpx %1$dpx;',
        'float:none;margin:%1$dpx;');

    $adsalign = isset($quads_options['ads']['ad' . $id]['align']) ? $quads_options['ads']['ad' . $id]['align'] : 3; // default
    $adsmargin = isset( $quads_options['ads']['ad' . $id]['margin'] ) ? $quads_options['ads']['ad' . $id]['margin'] : '3'; // default
    $margin = sprintf( $arr[( int ) $adsalign], $adsmargin );

            $ad_checker = '';
            // Removing duplicate db calls by saving function output in variable passing 
            $quads_ad_var = quads_get_ad( $id ); 
            $ad_checker = $quads_ad_var ? $quads_ad_var : '' ;
            if ( isset($ad_checker) ) {
                if ( strpos( $ad_checker, 'quads-rotatorad')!==false) { 
                    $margin = 'text-align: center';
                }
            }
            else{
                $margin = sprintf( $arr[( int ) $adsalign], $adsmargin );
            }
            if(!empty($quads_shortcode_ids)){
                if(is_array($quads_shortcode_ids))
                {
                    $quads_shortcode_ids=array_push($quads_shortcode_ids,$ad_id);
                }
                else if($quads_shortcode_ids>0 && $quads_shortcode_ids!=$ad_id){
                    $quads_shortcode_ids=array($quads_shortcode_ids,$ad_id);
                }
                else{
                    $quads_shortcode_ids=array($ad_id);
                }
                
            }else{ 
                $quads_shortcode_ids=array($ad_id);
            }
    // Do not create any inline style on AMP site
    $style = !quads_is_amp_endpoint() ? apply_filters( 'quads_filter_margins', $margin, 'ad' . $id ) : '';
    if(function_exists('quads_hide_markup') && quads_hide_markup()) {
        $code = "\n" . '<div style="' . $style . '">' . "\n";
        $code .= do_shortcode( $quads_ad_var );
        $code .= '</div>' . "\n";
    }else{
        $idof_ad_id = '';
        $idof_ad_id = $ad_id;
        $code = "\n" . '<!-- WP QUADS v. ' . QUADS_VERSION . '  Shortcode Ad -->' . "\n" .
            '<div class="quads-location quads-ad' . $idof_ad_id . '" id="quads-ad' . $idof_ad_id . '" style="' . $style . '">' . "\n";
        $code .= do_shortcode( $quads_ad_var );
        $code .= '</div>' . "\n";
    }

    return $code;
}

Code file location:

quick-adsense-reloaded/quick-adsense-reloaded/includes/shortcodes.php

Ads by WPQuads [adsforwp] Shortcode

The Quick AdSense Reloaded shortcode enables the display of ads based on specified conditions. It checks for ‘NoAds’ meta setting and returns if true. It also retrieves the ad id from the shortcode attributes and queries the ad post. The shortcode aligns and applies margins to the ad based on the settings.

Shortcode: [adsforwp]

Parameters

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

  • id – Specifies the unique identifier of the ad

Examples and Usage

Basic example – Displaying an ad by referencing its ID in the shortcode.

[adsforwp id=1 /]

Advanced examples

Using the shortcode to display an ad by referencing both ID and alignment. The ad will load by ID and will be aligned according to the provided alignment value. For example, ‘3’ for center alignment.

[adsforwp id=1 align=3 /]

Using the shortcode to display an ad by referencing ID, alignment, and margin. The ad will load by ID, will be aligned according to the provided alignment value, and the margin will be set based on the provided margin value. For example, ’10’ for a 10px margin.

[adsforwp id=1 align=3 margin=10 /]

PHP Function Code

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

Shortcode line:

add_shortcode('adsforwp', 'quads_from_adsforwp_manual_ads',1);

Shortcode PHP function:

function quads_from_adsforwp_manual_ads($atts ){
     global $quads_options;
    
    // Display Condition is false and ignoreShortcodeCond is empty or not true
    if( !quads_ad_is_allowed() && !isset($quads_options['ignoreShortcodeCond']) )
        return;


    //return quads_check_meta_setting('NoAds');
    if( quads_check_meta_setting( 'NoAds' ) === '1' ){
        return;
    }
    
    // The ad id
    $adsforwpid = isset( $atts['id'] ) ? ( int ) $atts['id'] : 0;

    $args = array(
      'post_type'      => 'quads-ads',
      'meta_key'   => 'adsforwp_ads_id', 
      'meta_value' => $adsforwpid
    );

    $event_query = new WP_Query( $args );
    if(!isset($event_query->post->ID)){
      return '';
    }
    $quads_post_id =$event_query->post->ID;
   $id_name = get_post_meta ( $quads_post_id, 'quads_ad_old_id', true );
   $id_array = explode('ad', $id_name );
   $id = $id_array[1]; 
    $arr = array(
        'float:left;margin:%1$dpx %1$dpx %1$dpx 0;',
        'float:none;margin:%1$dpx 0 %1$dpx 0;text-align:center;',
        'float:right;margin:%1$dpx 0 %1$dpx %1$dpx;',
        'float:none;margin:%1$dpx;');
    
    $adsalign = isset($quads_options['ads']['ad' . $id]['align']) ? $quads_options['ads']['ad' . $id]['align'] : 3; // default
    $adsmargin = isset( $quads_options['ads']['ad' . $id]['margin'] ) ? $quads_options['ads']['ad' . $id]['margin'] : '3'; // default
    $margin = sprintf( $arr[( int ) $adsalign], $adsmargin );

    
    // Do not create any inline style on AMP site
    $style = !quads_is_amp_endpoint() ? apply_filters( 'quads_filter_margins', $margin, 'ad' . $id ) : '';
    if(function_exists('quads_hide_markup') && quads_hide_markup()  ) {
        $adscode =
            "\n".'<div style="'.esc_html($style).'">'."\n".
            do_shortcode(quads_get_ad($id)).
            '</div>'. "\n";
    }else {
        $code = "\n" . '<!-- WP QUADS v. ' . QUADS_VERSION . '  Shortcode Ad -->' . "\n" .
            '<div class="quads-location quads-ad' . esc_html($id) . '" id="quads-ad' . esc_html($id) . '" style="' . esc_html($style) . '">' . "\n";
        $code .= do_shortcode(quads_get_ad($id));
        $code .= '</div>' . "\n";
    }

    return $code;
}

Code file location:

quick-adsense-reloaded/quick-adsense-reloaded/includes/template-functions.php

Ads by WPQuads [the_ad_placement] Shortcode

The Quick Adsense Reloaded plugin shortcode is used to manage ad placements on your website. The shortcode: [the_ad_placement] allows you to specify where ads should appear. It fetches ads based on the given ID and checks if they are allowed to display based on predefined conditions. It also handles ad alignment and margins for better aesthetics.

Shortcode: [the_ad_placement]

Parameters

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

  • id – The unique identifier of the advanced ad placement

Examples and Usage

Basic Example – Displaying an ad placement by referencing its ID in the shortcode.

[the_ad_placement id="1" /]

Advanced Examples

Using the shortcode to display an ad placement by referencing its ID. If the ad placement is not found by ID, the shortcode will return an empty string.

[the_ad_placement id="2" /]

Using the shortcode without any parameters. In this case, the shortcode will return an empty string because no ad placement ID is specified.

[the_ad_placement /]

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('the_ad_placement', 'quads_from_advance_manual_ads',1);

Shortcode PHP function:

function quads_from_advance_manual_ads($atts ){
    global $quads_options;
   
   // Display Condition is false and ignoreShortcodeCond is empty or not true
   if( !quads_ad_is_allowed() && !isset($quads_options['ignoreShortcodeCond']) )
       return;


   //return quads_check_meta_setting('NoAds');
   if( quads_check_meta_setting( 'NoAds' ) === '1' ){
       return;
   }
   $id = '';
   // The ad id
   // $advance_ads_id = isset( $atts['id'] ) ? ( int ) $atts['id'] : 0;
$atts = is_array( $atts ) ? $atts : array();
   $advance_ads_id   = isset( $atts['id'] ) ? (string) $atts['id'] : '';
     $advanced_ads_placements       = get_option('advads-ads-placements'); 
     $args = array(
       'post_type' => 'advanced_ads',
       'post_status' => 'publish'
     );
        $get_Advanced_Ads = get_posts($args);

       foreach ($get_Advanced_Ads  as $advanced_Ad) {
           
           $name = 'shortcode_'.$advanced_Ad->ID;
           $advanced_ads_placements[$name] = array('item' => 'ad_'.$advanced_Ad->ID,'advanced_ads'=>true);
       }
     foreach ($advanced_ads_placements as $key => $value) {
       $idArray =  (isset($value['item']) && !empty($value['item'])) ?  explode('ad_', $value['item']) : array('1'=>'');

       if($idArray['1'] == $advance_ads_id){

         $id = $idArray['1'];

       }
     }
     if(empty($id)){
        return '';
      }
      $args = array(
        'post_type'      => 'quads-ads',
        'meta_key'       => 'advance_ads_id', 
        'meta_value'     => $id
      );
   
      $event_query = new WP_Query( $args );

   if(!isset($event_query->post->ID)){
     return '';
   }
   $quads_post_id =$event_query->post->ID;
  $id_name = get_post_meta ( $quads_post_id, 'quads_ad_old_id', true );
  $id_array = explode('ad', $id_name );
  $id = $id_array[1]; 
   $arr = array(
       'float:left;margin:%1$dpx %1$dpx %1$dpx 0;',
       'float:none;margin:%1$dpx 0 %1$dpx 0;text-align:center;',
       'float:right;margin:%1$dpx 0 %1$dpx %1$dpx;',
       'float:none;margin:%1$dpx;');
   
   $adsalign = isset($quads_options['ads']['ad' . $id]['align']) ? $quads_options['ads']['ad' . $id]['align'] : 3; // default
   $adsmargin = isset( $quads_options['ads']['ad' . $id]['margin'] ) ? $quads_options['ads']['ad' . $id]['margin'] : '3'; // default
   $margin = sprintf( $arr[( int ) $adsalign], $adsmargin );

 
   // Do not create any inline style on AMP site
   $style = !quads_is_amp_endpoint() ? apply_filters( 'quads_filter_margins', $margin, 'ad' . $id ) : '';

   $code = "\n" . '<!-- WP QUADS v. ' . QUADS_VERSION . '  Shortcode Ad -->' . "\n" .
           '<div class="quads-location quads-ad' . $id . '" id="quads-ad' . $id . '" style="' . $style . '">' . "\n";
   $code .= do_shortcode( quads_get_ad( $id ) );
   $code .= '</div>' . "\n";

   return $code;
}

Code file location:

quick-adsense-reloaded/quick-adsense-reloaded/includes/template-functions.php

Ads by WPQuads [quadsvi] Shortcode

The Quick AdSense Reloaded shortcode is a powerful tool for managing ad displays. It uses the ‘quadsvi’ shortcode to call a specific function, ‘getShortcode’. This function checks various conditions like the presence of a token, meta settings, and AMP endpoints. If all conditions are met, it generates an ad code with a specified ID and style. The ad code is then wrapped in a script tag and enclosed within a div element. If the ‘quads_hide_markup’ function exists and is true, the ad code is hidden. Otherwise, it displays the ad with the WP QUADS version comment.

Shortcode: [quadsvi]

Parameters

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

  • id – It specifies the unique identifier of the ad.

Examples and Usage

Basic example – Displays an ad using the default ad ID.

[quadsvi /]

Advanced examples

Display an ad with a specific ID. This will override the default ID and display the ad with the ID specified in the shortcode.

[quadsvi id=2 /]

Display multiple ads by specifying multiple IDs. This will display the ads with the IDs specified in the shortcode.

[quadsvi id=2,3,4 /]

Note: The ‘id’ attribute in the shortcode is used to specify the ID of the ad you want to display. If no ‘id’ is specified, the shortcode will display the ad with the default ID of 1.

PHP Function Code

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

Shortcode line:

add_shortcode('quadsvi', array($this, 'getShortcode'));

Shortcode PHP function:

function getShortcode($atts) {
        global $quads_options;

        if (!$this->token) {
            return;
        }

        if (quads_check_meta_setting('NoAds') === '1') {
            return;
        }

        if (quads_is_amp_endpoint()) {
            return;
        }

        // The ad id
        $id = isset($atts['id']) ? (int) $atts['id'] : 1;

        $viad = $this->getAdCode();

        $style = 'min-width:363px;min-height:363px;';
        if(function_exists('quads_hide_markup') && quads_hide_markup()  ) {
            $code = '<div style="' . esc_html($style) . '">' . "\n";
            $code .= "<script>";
            $code .= do_shortcode($viad['ads'][1]['code']);
            $code .= '</script>' . "\n";
            $code .= '</div>' . "\n";
        }else{
        $code = "\n" . '<!-- WP QUADS v. ' . QUADS_VERSION . '  Shortcode vi ad -->' . "\n";
        $code .= '<div class="quads-location' . esc_html($id) . '" id="quads-vi-ad' . esc_html($id) . '" style="' . esc_html($style) . '">' . "\n";
        $code .= "<script>";
        $code .= do_shortcode($viad['ads'][1]['code']);
        $code .= '</script>' . "\n";
        $code .= '</div>' . "\n";
        }

        return $code;
    }

Code file location:

quick-adsense-reloaded/quick-adsense-reloaded/includes/vendor/vi/vi.php

Conclusion

Now that you’ve learned how to embed the Ads by WPQuads 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 *