Prevent widgets removal

The solution I can think of is removing the panels Available and Inactive Widgets so there’s simply nowhere to drag (and delete) the widgets used in the sidebar. You can inject something else to fill the gap. In this example, only one user is able to add/delete widgets. function wpse_53398_script_printer(){ // used to display the … Read more

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.

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; }

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

Modifying the default search widget

You can hook into the ‘get_search_form’ action hook ( check out the “last option” part of the link below ). Set the priority high enough to override anything created in a theme. A plugin could look like ( from the link below ): function my_search_form( $form ) { $form = ‘<form role=”search” method=”get” id=”searchform” class=”searchform” … Read more