
⭐️4.4 (8)
Plugins | Site Design | Menus
If Widget
Control what widgets your site’s visitors see, based on custom visibility rules
Frequently Asked Questions
On Widgets editing page, each widget will have a section for controlling visibility. Enable the option “Show widget only if” to reveal and configure visibility rules (Example in screenshots).
New rules can be added by code in any other plugin or theme.
Example of adding a new custom 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;
}
WordPress provides a lot of functions which can be used to create custom rules for almost any combination that a theme/plugin developer can think of.
Support
- Version: 0.5
- Last updated: 02 Mar 2019
- Tested up to WordPress 5.6.8
- Requires PHP 5.6 or higher
- FAQ
- Support forum ❐
Still need help?
Please visit the Support forum on WordPress.org