Support » Plugin: Ads by datafeedr.com » dfads shortcode always return something

  • Resolved anou

    (@anou)


    Hello,
    I use dfads shorcodes in widgets
    [dfads params='groups=712&limit=1&return_javascript=1']

    and I display the widget like this:

    <?php if( !dynamic_sidebar('pub-totalcovering-top') ): ?>
      <div class="totalcovering-pub-top"><img src="/images/arch-top.jpg" alt="my default ad" /></div>
    <?php endif; ?>

    My problem is that dynamic_sidebar('pub-totalcovering-top') is always true, because the shortcode always returns the basique HTML even if there is no ad.

    But maybe I missed something in my config, shortcode or something else?

    Thank you for your help.

    • This topic was modified 8 months, 4 weeks ago by anou.
    • This topic was modified 8 months, 4 weeks ago by anou.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Sorry but it seems that if I remove return_javascript=1' the shortcode outputs nothing.

    It is not really a solution but it is maybe a hint to a shared “problem” between dfads shortcode and dynamic_sidebar function 🙂

    Plugin Author datafeedr

    (@datafeedrcom)

    If you have return_javascript=1 then the plugin will always return HTML to the browser. That’s because the JS part loads data via AJAX to ensure the ads aren’t affected by caching plugins.

    So you’ll need to keep the javascript code removed from your shortcode.

    Or you could always use the PHP code like <?php $ads = dfads( 'groups=3&limit=2' ); ?> to write your own conditional.

    Thank you for your answer, and I already did what you just advised 🙂

    <?php if( !dynamic_sidebar('pub-totalcovering-top') || !dfads( 'groups=712&limit=1' ) ): ?>
        <div class="totalcovering-pub-top"><img src="<?php echo get_stylesheet_directory_uri() . '/images/arch-top.jpg';?>" alt="" /></div>
      <?php endif; ?>

    Thanks again

    Plugin Author datafeedr

    (@datafeedrcom)

    Cool, glad you got it working!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘dfads shortcode always return something’ is closed to new replies.