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

Override custom menu widget

Ok, here we go. I extended the default Navigation widget for you. Add this to your themes functions file. After you have done this, go to widgets in your dashboard and you will see a widget called ‘Matt Royal Custom Menu’ now. Use this one. In the below code, the div class has been added … Read more

How to retrive widget title/data

Found a ‘dirty’ way to do it: Here’s my code: $sidebar_id = ‘sidebar1′; $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; foreach( $widget_ids as $id ) { $wdgtvar=”widget_”._get_widget_id_base( $id ); $idvar = _get_widget_id_base( $id ); $instance = get_option( $wdgtvar ); $idbs = str_replace( $idvar.’-‘, ”, $id ); echo ‘<li><a href=”#’.$id.'”>’.$instance[$idbs][‘title’].'</a></li>’; }

Add thumbnail to recent posts widget using filters

Here’s one way to do it through the the_title filter. We can limit the scope to the Recent Posts widget, by initialize it within the widget_posts_args filter and then remove it again after the loop. /** * Recent Posts Widget: Append Thumbs */ add_filter( ‘widget_posts_args’, function( array $args ) { add_filter( ‘the_title’, ‘wpse_prepend_thumbnail’, 10, 2 … Read more

Can I ignore caching of a plugin in W3 Total Cache? [closed]

You can try fragment caching, from plugin’s FAQ: Edit your templates to with the following syntax to ensure that dynamic features remain so: Example 1: <!– mfunc any PHP code –><!– /mfunc –> Example 2: <!– mfunc –>any PHP code<!– /mfunc –> Example 3: <!–MFUNC –> echo rand(); <!–/mfunc –> Example 4: <!– mclude path/to/file.php … Read more