If Widget is a WordPress plugin which adds extra functionality for widgets, making it easy to hide or display them based on visibility rules. Examples:
- Display a widget only if current
User is logged in - Hide widget if
visiting from mobile device - Display widgets only for
Admins and Editors
The plugin is easy to use, each widget will have a “Show widget only if” option which will enable the selection of visibility rules.
This repo is used only for development, downloading & installing from here won't work as expected. Install from WordPress.org plugin page
- Basic set of visibility rules
- User state
User is logged in - User roles
AdminEditorAuthoretc - Page type
Front pageBlog page - Post type
PostPageProductetc - Device
Is Mobile
- User state
- Multiple rules - mix multiple rules for a widget visibility
- show if
User is logged inANDDevice is mobile - show if
User is AdminANDIs Front Fage
- show if
- Support for adding custom visibility rules
Custom visibility rules can be added easily by any plugin or theme. Example of adding a new rule for displaying/hiding a widget when current page is a custom-post-type.
// theme's functions.php or plugin file
add_filter('if_visibility_rules', 'my_new_visibility_rule');
function my_new_visibility_rule(array $rules) {
$rules['single-my-custom-post-type'] = array(
'name' => __('Single my-CPT', 'i18n-domain'), // name of the condition
'callback' => function() { // callback - must return Boolean
return is_singular('my-custom-post-type');
}
);
return $rules;
}Head over to plugin's page on WordPress.org for more info, reviews and support.