內容簡介
透過這個外掛,你可以使用 WordPress 的條件標籤來在前台啟用或停用選單項目。它的作用類似於「Widget Logic」,但是適用於選單項目。
請注意:這些條件是 PHP 程式碼,使用 PHP 的「eval」函數進行評估,這意味著有權訪問 WordPress 選單管理員的任何人都可以執行任何程式碼。請注意管理好有權訪問選單管理員的人員。
使用方法
你必須在選單項目選項表單的「可見性」框中插入條件標籤。你可以使用任何 PHP 或 WordPress 函数來構建選單項目的複雜條件和邏輯。例如,要在首頁隱藏選單項目,可以將可見性設為:
! is_home()
僅向已登錄的用戶顯示菜單:
is_user_logged_in()
僅向訪客訪問者顯示菜單:
! is_user_logged_in()
基於用戶權限顯示菜單項目:
current_user_can( 'manage_options' )
外掛標籤
開發者團隊
原文外掛簡介
Using this plugin you can use WordPress Conditional Tags to enable or disable menu items on the front-end. It works like ‘Widget Logic’ but for menu items.
PLEASE NOTE The conditions are PHP codes that are evaluated using PHP’s “eval” function, meaning anyone who has access to the Menu manager in WordPress can execute any code. Be mindful of who has access to the Menu manager.
Usage
You must insert conditional tags in the “Visibility” box in the menu item options form. You can use any PHP or WordPress functions to build crazy conditions and logics for menu items. For example, to hide the menu item on homepage you can set the visibility to:
! is_home()
Show the menu only to logged-in users:
is_user_logged_in()
Show the menu only to guest visitors:
! is_user_logged_in()
To show the menu item based on user capability:
current_user_can( 'manage_options' )
