Title: Does widget code gets executed when sidebar is collapsed?
Last modified: August 22, 2016

---

# Does widget code gets executed when sidebar is collapsed?

 *  [wp169](https://wordpress.org/support/users/wp169/)
 * (@wp169)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/does-widget-code-gets-executed-when-sidebar-is-collapsed/)
 * Dear friends,
 * I display some ads in my sidebar using text widget (with tag from the ad network).
   Depending on the mobile device resolution, sidebar may be collapsed.
 * I want to know if even though the sidebar is hidden, does it still execute the
   widget code and probably contact ad server to get the ad? It will not be visible
   until user expands the sidebar.
 * I don’t know how to verify it. Any insight will be helpful from the community.
 * If the answer is Yes, is there a way not to execute the code if the resolution
   is:
    primary bar – between 480 and 960 Secondary bar – between 480 and 1200
 * Thanks!

Viewing 1 replies (of 1 total)

 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/does-widget-code-gets-executed-when-sidebar-is-collapsed/#post-5902750)
 * Hi wp169. The presentation of the page doesn’t affect the underlying code; it
   still runs when the page is refreshed. Maybe someone more familiar with the ad
   network can suggest a way to verify that. To keep the code from executing at 
   certain widths you’d probably need to use a widget like [Enhanced Text Widget](https://wordpress.org/plugins/enhanced-text-widget/)
   and some [jQuery like this](http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed)
   to write the ad code html based on the screen width. Perhaps someone else on 
   the forum here knows of a different way to accomplish this.

Viewing 1 replies (of 1 total)

The topic ‘Does widget code gets executed when sidebar is collapsed?’ is closed 
to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/hueman/3.7.27/screenshot.png)
 * Hueman
 * [Support Threads](https://wordpress.org/support/theme/hueman/)
 * [Active Topics](https://wordpress.org/support/theme/hueman/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/hueman/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/hueman/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/does-widget-code-gets-executed-when-sidebar-is-collapsed/#post-5902750)
 * Status: not resolved