If Menu — Visibility control for Menus

Описание

Control what menu items your site’s visitors see, with visibility rules. Here are a few examples:

  • Display a menu item only if User is logged in
  • Hide menus if Device is mobile
  • Display menus for Admins and Editors
  • Hide Login or Register links for Logged in Users
  • Display menus for Users from US or UK
  • Display menus only for Customers with active membership
  • Display menus for visitors browsing with Language English or Spanish

After the plugin is enabled, each menu item will have a new option “Change menu item visibility” which will enable the selection of visibility rules.

Check the examples in screenshots or try it here → demos.layered.store

Основные функции

  • Основной набор правил видимости
    • Состояние пользователя Авторизован ли пользователь
    • Роли пользователя Администратор Редактор Автор и т.д.
    • Тип страницы Главная страница Одна страница Страница записи
    • Is Archive page (year, category, search results, etc)
    • Visitor device Is Mobile
  • Advanced visibility rules — requires More Visibility Rules Add-on
    • Visitor location — detect visitor’s Country
    • Visitor language — detect visitor’s selected Language
    • WooCommerce Subscriptions — Display menus for users with active subscription
    • WooCommerce Memberships — Display menus for customers with active membership plans
    • Groups — Detect if users are in specific groups
    • WishList Member — Detect the users’ membership level
    • Restrict Content Pro — Detect the users’ subscription level
  • Несколько правил — сочетание нескольких правил для видимости элементов меню
    • показать еслиПользователь авторизован на вашем сайте И используется Мобильное устройство
    • показать элемент меню если Пользователь Администратор И если это главная страница
  • Support for adding your custom rules

Скриншоты

  • If Menu website demo
  • Включить правила видимости для элементов меню
  • Пример правил видимости

Часто задаваемые вопросы

Show or hide menus if user is logged in

One of the most popular uses of the plugin is to show the «Register/Login» menu for non-logged-in users, and «Your account» for logged-in users.

To enable this for «Register/Login» menu, follow these steps:
1. Go to WordPress Admin on your website -> Appearance -> Menus
2. Expand the menu item for «Register» or «Login» page
3. Enable the option «Enable visibility rules»
4. Choose the rule «Hide if user logged in»

For showing the «Your account page», follow these steps:
1. Go to WordPress Admin on your website -> Appearance -> Menus
2. Expand the menu item for «Your account page» page
3. Enable the option «Enable visibility rules»
4. Choose the rule «Show if user logged in»

Mix multiple visibility rules

Multiple visibility rules can be used at once, like so:

For showing a menu item only for admins on desktop:
1. Go to WordPress Admin on your website -> Appearance -> Menus
2. Expand the menu item you want
3. Enable the option «Enable visibility rules»
4. Choose the rule «Show if user is Administrator»
5. Click the «+» button at the end of the visibility rule, and change to «AND»
6. On the newly added row, choose «Hide if device is mobile»

For showing a menu item for Admins or users with an active subscription:
1. Go to WordPress Admin on your website -> Appearance -> Menus
2. Expand the menu item you want
3. Enable the option «Enable visibility rules»
4. Choose the rule «Show if user is Administrator»
5. Click the «+» button at the end of the visibility rule, and change to «OR»
6. On the newly added row, choose «Show if Has active subscription __»

To remove an extra visibility rule:
1. Go to WordPress Admin on your website -> Appearance -> Menus
2. Expand the menu item with multiple visibility rules
3. Click on the «AND» / «OR» buttons at end of visibility option
4. Change to «+»

If Menu is broken, no visibility rules are available

There’s a known limitation with adding functionality for menu items in WordPress, and conflicts may happen between some plugins and themes.

If there are multiple plugins that extend Menu Items, for example If Menu and a plugin for Menu Icons, only one of them can add the needed functionality and the other one won’t work as expected.

Это постоянная проблема с WordPress, которая, надеюсь, будет исправлена в будущих обновлениях.

If the «Menus» page is blank or options for visibility rules are not displaying, there is a way to test which plugin/theme causes this conflict.
Please disable other plugins or themes until you find the one that causes the problem, and contact the respective developers.
In the message include the link to WordPress ticket about menu items https://core.trac.wordpress.org/ticket/18584 where they can see detailed info on how to fix the problem.

Changes to menus are not saved

This problem may happen on sites with a large number of menu items.
In most cases, this is not a limitation or problem caused by plugins or WordPress, but by the hosting server.

Your hosting provider or server limits the amount of data that can be sent to WordPress for saving in database.
The setting is named «PHP max_input_vars» and it’s value should be increased, ex: max_input_vars = 200 to max_input_vars = 500.
Contact your hosting provider or make the change yourself if you have access. More details can be found here https://core.trac.wordpress.org/ticket/14134

Как я могу добавить произвольное правило видимости для элементов меню?

Новые правила могут быть добавлены любым другим плагином или темой.

Пример добавления нового произвольного правила для отображения/скрытия элемента меню когда текущая страница является произвольным типом записи.

// theme's functions.php or plugin file
add_filter('if_menu_conditions', 'my_new_menu_conditions');

function my_new_menu_conditions($conditions) {
  $conditions[] = array(
    'id'        =>  'single-my-custom-post-type',                       // unique ID for the rule
    'name'      =>  __('Single my-custom-post-type', 'i18n-domain'),    // name of the rule
    'condition' =>  function($item) {                                   // callback - must return Boolean
      return is_singular('my-custom-post-type');
    }
  );

  return $conditions;
}

Где я могу найти условные теги (функции)?

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.

Отзывы

23.06.2022
5 stars for making such great plugin (-) 2 stars for bugs! The plugin recognizes tablets as mobile. Devices like -nest hub -surface duo, surface pro 7 -ipad mini, air, pro...etc are recognized as mobile and this causes error in my menus where I want "Every device with window width/height > 480 to NOT be considered as MOBILE". Wordpress version 6.0 If Menu Plugin Version 0.16.2
27.02.2022
I would have rated this 3-4 stars because although it's basic, it did the job well enough. Unfortunately it seems to have stopped working, possibly since the latest WordPress updates. The plugin hasn't been kept up to date either. So can't rate this any higher that 1 star for now. It's the only plugin of its kind (it seems), so I hope it gets an update.
24.02.2022
Brought to get extra features only to find zero support no matter how many support emails are submitted, even the developers blog and twitter have been removed.
Посмотреть 121 отзыв

Участники и разработчики

«If Menu — Visibility control for Menus» — проект с открытым исходным кодом. В развитие плагина внесли свой вклад следующие участники:

Участники

«If Menu — Visibility control for Menus» переведён на 5 языков. Благодарим переводчиков за их работу.

Перевести «If Menu — Visibility control for Menus» на ваш язык.

Заинтересованы в разработке?

Посмотрите код, проверьте SVN репозиторий, или подпишитесь на журнал разработки по RSS.

Журнал изменений

0.16.3 — 26 June 2022

  • Added — More usage examples in plugin FAQs section
  • Updated — WordPress v6 compatibility
  • Updated — Integration with Restrict Content Pro plugin is improved

0.16.2 — 17 January 2020

  • Fixed — Error shown about the registered REST Api endpoint
  • Updated — Ensure compatibility with WordPress 5.6

0.16.1 — 11 April 2020

  • Fixed — Improved compatibility with other plugins that extend menu items

0.16 — 1 April 2020

  • Added — Visibility rule — Is Archive page
  • Updated — Ensure compatibility with WordPress 5.4
  • Updated — Improved compatibility with WooCommerce Membership/Subscription plugins

0.15 — 2 July 2019

  • Updated — Texts & styles for If Menu settings page
  • Fixed — PHP error that may appear for Visibility Rules saved before If Menu v0.9