A client of mine has ads on his website, which are managed by a CPT. The ads can be pulled in via a widget, hardcoded query and a shortcode. I have an issue that isn't consistent that I'm trying to debug. Sometimes ads show up below the footer and other times they don't (and they shouldn't). The website is responsive and has different ad units for all 3 breakpoints. The site first goes through CloudFlare and then is cached using W3TC. I'm wondering if anyone has seen this or may have a thought about why this is happening.


This is a screenshot of the issue..

//[ad id=""]
function insert_ad( $atts ) {
    $ad = shortcode_atts( array(
        'id' => '',
        'align' => ''
    ), $atts );

    if($ad['align'] == '' || $ad['align'] == 'left'){
        $align = 'alignLeft';
    } elseif($ad['align'] == 'middle' || $ad['align'] == 'center'){
        $align = 'alignCenter';
    } elseif($ad['align'] == 'right'){
        $align = 'alignRight';

    global $post; 
    $args = array( 'post_type' => 'cbd_ads', 'p' => $ad['id'] );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();

    if(!wp_is_mobile() && get_post_status() == 'publish'){
        return '<div class="'. $align .'">' . get_the_content() . '</div>';
    } else {
        return '';

    endwhile; wp_reset_query();
add_shortcode( 'ad', 'insert_ad' );
  • I suspect that you are echoing output from your shortcode. This does have this effect. Post your shortcode code – Pieter Goosen Apr 6 '15 at 6:48
  • @PieterGoosen I've updated the post with the code from my shortcode! – Austin Biggs Apr 10 '15 at 18:43
  • There is nothing in your code that would suggest why this failure happens. Just one tip, you should be using wp_reset_postdata() with WP_Query, wp_reset_query() is used with query_posts which you should never use – Pieter Goosen Apr 11 '15 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.