Show post tags in a widget

Tags can be shown outside the Post loop using the global functions. Step 1 : Get a PHP Code Widget (this solved many problems) Step 2 : Place the Code <?php the_tags(); ?> in widget and Save. Check Tags Documentation to tweak display order. All done just rock and roll.

How to hook into unregistering a widget instance?

Yes, this can be done. Ultimately, adding and removing a widget to/from a sidebar means updating an option in the database with a call like this: update_option( ‘sidebars_widgets’, array( … ) ) If you look at the code of update_option you see that there is a filter called just before the actual update. So if … Read more

Get Widget Instance inside Widget

You can get widget options using following code $current_widget_options = $this->get_settings(); This will return array like array(instance number => settings). Instance number refers to the $number of widget. Example: If your widget instance number is 2 then your required options will be at $current_widget_options[2] Alternative: As get_settings() is deprecated, you can use get_option. Check following … Read more

How Do I Add Custom CSS To Only Certain Widgets

Hi John: I think this is what you are looking for (I’d explain the code be I think it’s self-explanatory; let me know if not): <?php add_filter(‘dynamic_sidebar_params’,’my_dynamic_sidebar_params’); function my_dynamic_sidebar_params($params) { $sidebar_id = $params[0][‘id’]; $sidebar_widgets = wp_get_sidebars_widgets(); $last_widget_id = end($sidebar_widgets[$sidebar_id]); if ($last_widget_id==$params[0][‘widget_id’]) $params[0][‘before_widget’] = str_replace(‘ class=”‘,’ class=”last_widget ‘,$params[0][‘before_widget’]); return $params; }

How to hide or remove unwanted widgets on Multisite installation?

Add this to your functions.php file: function jpb_unregister_widgets(){ unregister_widget(‘WP_Widget_Pages’); unregister_widget(‘WP_Widget_Calendar’); unregister_widget(‘WP_Widget_Archives’); unregister_widget(‘WP_Widget_Links’); unregister_widget(‘WP_Widget_Meta’); unregister_widget(‘WP_Widget_Search’); unregister_widget(‘WP_Widget_Text’); unregister_widget(‘WP_Widget_Categories’); unregister_widget(‘WP_Widget_Recent_Posts’); unregister_widget(‘WP_Widget_Recent_Comments’); unregister_widget(‘WP_Widget_RSS’); unregister_widget(‘WP_Widget_Tag_Cloud’); unregister_widget(‘WP_Nav_Menu_Widget’); } add_action( ‘widgets_init’, ‘jpb_unregister_widgets’ ); This will get rid of all default widgets. If you want to keep a certain widget, remove that line from the function above.

Call dynamic_sidebar but include/exclude named widgets?

dynamic_sidebar() calls wp_get_sidebars_widgets() to get all widgets per sidebar. I think filtering this output is the best way to remove a widget from an sidebar. add_filter( ‘sidebars_widgets’, ‘wpse17681_sidebars_widgets’ ); function wpse17681_sidebars_widgets( $sidebars_widgets ) { if ( is_page() /* Or whatever */ ) { foreach ( $sidebars_widgets as $sidebar_id => &$widgets ) { if ( ‘my_sidebar’ … Read more

How to influence the information displayed on widget inside wp-admin

Background: The reason why filtering with dynamic_sidebar_params doesn’t work with HTML is because WordPress strips HTML from Widget Heading in wp_widget_control() function like this: $widget_title = esc_html( strip_tags( $sidebar_args[‘widget_name’] ) ); WordPress also strips HTML in default JavaScript in wp-admin/js/widgets.js So without a customised solution, there is no default filter or option either with PHP … Read more

Adding iframe Content to Sidebar Widget

Just create a widget that doesn’t filter your input. This is probably the most simple widget with user input you can build. Here is the widget I use in my plugin Magic Widgets. /** * Simplified variant of the native text widget class. * * @author Fuxia Scholz * @version 1.0 */ class Unfiltered_Text_Widget extends … Read more