Widget Area: Modify $param[‘xy’] from widget-$n

The dynamic_sidebar_params filter is called before each widget is displayed, so multiple times in the same sidebar. It filters the $args and $instance parameters that will be passed to the widget. If you only want to execute it for the third widget of a specific sidebar, you should check for the sidebar ID (found in … Read more

How to check if widget has automatic title

Any widgets written to operate as the Core “Recent Posts” widget does can be forced to skip the title by a filter on widget_title: function widget_title_hack_191120($title, $instance) { if (empty($instance[‘title’])) { $title=””; } return $title; } add_filter(‘widget_title’,’widget_title_hack_191120′, 10, 2); I don’t know if there is a generic solution to the problem. Any widget could avoid … Read more

Enabling Default Widgets in a Custom Theme

that’s not the way, wp_register_sidebar_widget is used to create widgets. if you want your sidebar to display widgets by default use [dynamic_sidebar()][1] in your theme eg from the 2010 theme: <div id=”primary” class=”widget-area” role=”complementary”> <ul class=”xoxo”> <?php /* When we call the dynamic_sidebar() function, it’ll spit out * the widgets for that widget area. If … Read more

How to add the widgets manually to the sidebar?

Have a look at the the_widget() function. The first argument is required. It is the PHP class name of the widget. For example: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Search’) ?> </div> You can also pass on extra arguments: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Text’, ‘title=Hello&text=World’) ?> </div>

Need help adding additional controls to a custom widget Part 2

Here is an updated version of the widget which handles the vertical layout option, including categories, and excluding categories. Handling the vertical layout option is pretty straightforward; we just check to see if the option is checked, and if so, output the appropriate classes. Handling the inclusion/exclusion of categories is a little more complex because … Read more

Dynamically Register Sidebars For Each Top Level Page

try this code for creating unique sidebar for each parent page you can use $page->post_name(page slug) or $page->ID(page id) as sidebar id if ( function_exists(‘register_sidebar’) ){ /*extract all parent pages */ $topLevel = get_pages(array( ‘sort_column’ => ‘post_date’, ‘hierarchical’ => 0, ‘parent’ => 0 )); foreach($topLevel as $page){ /* register sidebar for each parent page */ … Read more

Should use widgets in this case?

The general concept on dynamic sidebars Basically WP loops through the global $wp_registered_widgets and builds the widget depending on it’s arguments. You can intercept them easily: Use a filter You can use the dynamic_sidebar_params to add a class to target specific widgets: // SHOW the params for better insights function wpse44903_dump_sidebar_params( $params ) { echo … Read more

Is there a way to allow only certain type of widgets in the sidebars?

It is possible to hook to sidebars_widgets and find which widget is in which sidebar. function dump_sidebar($a) { echo ‘<pre>’.var_export($a,true).'</pre>’; } add_action( ‘sidebars_widgets’, ‘dump_sidebar’); By checking that array you could eliminate particular widgets. function limit_sidebar_wpse_101279($sidebars_widgets) { if (!empty($sidebars_widgets[‘sidebar-1’])) { foreach ($sidebars_widgets[‘sidebar-1’] as $k =>$v) { if (‘pages’ == substr($v,0,5)) { unset($sidebars_widgets[‘sidebar-1’][$k]); } } } return … Read more