Skip to content

Repository files navigation

If Widget

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

Features

  • Basic set of visibility rules
    • User state User is logged in
    • User roles AdminEditorAuthor etc
    • Page type Front pageBlog page
    • Post type PostPageProduct etc
    • Device Is Mobile
  • Multiple rules - mix multiple rules for a widget visibility
    • show if User is logged in AND Device is mobile
    • show if User is Admin AND Is Front Fage
  • Support for adding custom visibility rules

Adding custom visibility rules in a plugin or theme

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 fileadd_filter('if_visibility_rules', 'my_new_visibility_rule');
functionmy_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 Booleanreturnis_singular('my-custom-post-type');
}
);
return$rules;
}

WordPress.org

Head over to plugin's page on WordPress.org for more info, reviews and support.

Releases

Packages

Used by

Contributors

Languages