Add div class to only one widget

You have two possible solutions. 1. The widget_display_callback filter hook This filter hook parameters allows you to target easily the widget instance and override it’s arguments. A possible approach would be: Inside the filter callback, modify the arguments for that instance, display it and then return false to prevent it from being displayed again the … Read more

Widget Update Code Not Working

You’re using get_field_id() for the name attribute of the form elements, but you should use get_field_name(). The field names are of the form widget-{$id_base}[{$number}][{$field_name}], but id’s can’t use [], so they are like widget-{$id_base}-{$number}-{$field_name}.

Widget with random posts from a blog for external sites

To create a special output of random posts: Register an endpoint to the root of your blog. See A (Mostly) Complete Guide to the WordPress Rewrite API for details. Refresh the permalink settings. I would do this on (de)activation only. Hook into ‘template_redirect’ and return your output depending on the details of the requested endpoint. … Read more

Add New Footer Widget Area with Limited Options?

Widget areas are the wrong tools for what you need. They are built to offer a choice. Breaking that would be very difficult … and hard to understand for the user. Alternative: Use a custom setting, for example in wp-admin/options-general.php where the tagline and the site title is. There is even a hook for such … Read more

Where to get the unsaved list of widgets in customizer?

You can get the list of widgets in a sidebar via: wp.customize(‘sidebars_widgets[sidebar-1]’).get() This is a list of the widgets’ IDs. The sidebars_widgets[sidebar-1] is the setting ID for the sidebar. Replace sidebar-1 with the ID of your sidebar. So to get the count just do: wp.customize(‘sidebars_widgets[sidebar-1]’).get().length If you want to listen for when a widget is … Read more

Woocommerce Product Category Widget – hide categories that have no products in stock [closed]

Use the woocommerce_product_categories_widget_args and woocommerce_get_availability filters in a custom function to filter the product categories widget for out of stock products. See what you can come up using these filters and post the code back here if you get stuck. Here’s some code from my site which may help you get started. add_filter( ‘woocommerce_product_categories_widget_args’, ‘wpsites_exclude_product_cat_widget’ … Read more

Remove All Widgets from Sidebar

You could add this function to your functions.php file. add_filter( ‘sidebars_widgets’, ‘disable_all_widgets’ ); function disable_all_widgets( $sidebars_widgets ) { $sidebars_widgets = array( false ); return $sidebars_widgets; } You could also use the WordPress conditional tags to disable widgets only on certain pages. For example; this would only disable widgets on the home page. add_filter( ‘sidebars_widgets’, ‘disable_all_widgets’ … Read more