0

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.

Thanks!

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' );
3
  • I suspect that you are echoing output from your shortcode. This does have this effect. Post your shortcode code Commented Apr 6, 2015 at 6:48
  • @PieterGoosen I've updated the post with the code from my shortcode! Commented Apr 10, 2015 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 Commented Apr 11, 2015 at 6:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.