Title: dfads shortcode always return something
Last modified: May 23, 2019

---

# dfads shortcode always return something

 *  Resolved [anou](https://wordpress.org/support/users/anou/)
 * (@anou)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/)
 * 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 6 years, 10 months ago by [anou](https://wordpress.org/support/users/anou/).
    -  This topic was modified 6 years, 10 months ago by [anou](https://wordpress.org/support/users/anou/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [anou](https://wordpress.org/support/users/anou/)
 * (@anou)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/#post-11563390)
 * 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](https://wordpress.org/support/users/datafeedrcom/)
 * (@datafeedrcom)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/#post-11564600)
 * 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.
 *  Thread Starter [anou](https://wordpress.org/support/users/anou/)
 * (@anou)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/#post-11564645)
 * 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](https://wordpress.org/support/users/datafeedrcom/)
 * (@datafeedrcom)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/#post-11564658)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/ads-by-datafeedrcom.svg)
 * [Ads by datafeedr.com](https://wordpress.org/plugins/ads-by-datafeedrcom/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ads-by-datafeedrcom/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ads-by-datafeedrcom/)
 * [Active Topics](https://wordpress.org/support/plugin/ads-by-datafeedrcom/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ads-by-datafeedrcom/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ads-by-datafeedrcom/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 4 replies
 * 2 participants
 * Last reply from: [datafeedr](https://wordpress.org/support/users/datafeedrcom/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/dfads-shortcode-always-return-something/#post-11564658)
 * Status: resolved