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

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

How to add class on Widget Title

Two approaches: Don’t bother Just target .widget.{dynamic-class} h3 instead Use %2$s I don’t know if this will work, but try: ‘before_title’ => ‘<h3 class=”%2$s”>’ But personally, I’d go with the former option. You’ve already got a unique class name; just leverage the element hierarchy to apply styles selectively.

Adding classes to dynamic sidebar

You haven’t actually said what the problem is. But I can see one for starters – dynamic_sidebar in your if conditions will echo out the widgets immediately. If you want to check a sidebar has widgets, use is_active_sidebar: is_active_sidebar( ‘sidebar-1’ ); // True/false

Display specific widgets in different area’s around the page

You will want to create a new widget area or dynamic sidebar in your theme’s code. Justin Tadlock has a great tutorial about how to do this, but the basics boil down to this. Add the widget area declaration in your theme’s functions.php file: <?php add_action(‘widgets_init’, ‘my_register_sidebars’); function my_register_sidebars() { /* Register the ‘cartwidgets’ sidebar. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)