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

Switching themes without losing widgets?

Storing widgets is complex topic. Basically it is such a multi-level-array-mess on the inside that very few people try to make sense of it (and even fewer succeed). 🙂 As far as I understand it myself while we can manipulate cute sidebar names on the surface, deep inside it is getting deconstructed to numerical IDs. … 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

How to add a specific widget to only 1 page?

It depends on where you want to show the widget. Let’s start with the widget area (sidebar) registration: add_action( ‘wp_loaded’, ‘wpse_76959_register_widget_area’ ); function wpse_76959_register_widget_area() { register_sidebar( array ( ‘name’ => __( ‘Widgets on page Sample Page’, ‘theme_textdomain’ ), ‘description’ => __( ‘Will be used on a page with a slug “sample-page” only.’, ‘theme_textdomain’ ), ‘id’ … Read more

Get a list of all Widgets registered in WordPress admin widgets-area

Widgets are stored in a public variable $widgets in the class WP_Widget_Factory. You can access this class per global variable $wp_widget_factory. To get all registered widgets, list the keys: add_action( ‘wp_footer’, function() { if ( empty ( $GLOBALS[‘wp_widget_factory’] ) ) return; $widgets = array_keys( $GLOBALS[‘wp_widget_factory’]->widgets ); print ‘<pre>$widgets=” . esc_html( var_export( $widgets, TRUE ) ) … Read more

Retrieve each widget separately from a sidebar

I am taking the core of the question to be: “… I’m not able to retrieve the widget class name” You will need to check the global variable $wp_registered_widgets to fill in the missing information. This proof-of-concept code should give you the idea. The code assumes a sidebar named sidebar-1. You will have to adjust … Read more

How to use is_active_widget?

You should make the check inside the widget class, unless you don’t have a choice. The example in the codex is pretty much what you’re looking for: class cbs_map_widget extends WP_Widget{ function cbs_map_widget(){ $this->WP_Widget(‘cbsmaps’, __(‘Widget Name’), array(‘classname’ => ‘cbsmaps’, ‘description’ => __(‘whatever’))); … add_action(‘wp_enqueue_scripts’, array(&$this, ‘js’)); } function js(){ if ( is_active_widget(false, false, $this->id_base, true) … Read more

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