Title: php code for template to limit certain pages
Last modified: August 21, 2016

---

# php code for template to limit certain pages

 *  [shepme](https://wordpress.org/support/users/shepme/)
 * (@shepme)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/php-code-for-template-to-limit-certain-pages/)
 * Instead of going into each widget and in the widget-logic field inserting
    is_front_page(),
   is there a way that I could add some code to my functions.php or other php file
   so it tells wordpress to only open these widgets on the home page even if it’s
   not specified in the individual widget? Thank you Shepard
 * [https://wordpress.org/plugins/widget-logic/](https://wordpress.org/plugins/widget-logic/)

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

 *  [Dan14](https://wordpress.org/support/users/dan14/)
 * (@dan14)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/php-code-for-template-to-limit-certain-pages/#post-4946398)
 * Great question, I am looking for the same thing. Did you find an answer?
 *  [alanft](https://wordpress.org/support/users/alanft/)
 * (@alanft)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/php-code-for-template-to-limit-certain-pages/#post-4946399)
 * I’m not quite sure what you have in mind, but you could circumvent the need for
   WL entirely, but use the same technique it employs. Basically you can filter 
   widgets with
 * add_filter( ‘sidebars_widgets’, my_own_filter_sidebars_widgets’, 10);
 * and then your function can loop through the sidebars, and each widget in them,
   unsetting any widget you like and then passing back the result
 *     ```
       function my_own_filter_sidebars_widgets($sidebars_widgets)
       {
       	foreach($sidebars_widgets as $widget_area => $widget_list)
       	{
       		foreach($widget_list as $pos => $widget_id)
       		{
       		…
       		…
       		if (some condition perhaps based on $widget_id)
       			unset($sidebars_widgets[$widget_area][$pos]);
       		…
       		…
       		}
       	}
       	return $sidebars_widgets;
       }
       ```
   

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

The topic ‘php code for template to limit certain pages’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/widget-logic_c8dde5.svg)
 * [Widget Logic](https://wordpress.org/plugins/widget-logic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/widget-logic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/widget-logic/)
 * [Active Topics](https://wordpress.org/support/plugin/widget-logic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/widget-logic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/widget-logic/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [alanft](https://wordpress.org/support/users/alanft/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/php-code-for-template-to-limit-certain-pages/#post-4946399)
 * Status: not resolved