Created
October 17, 2018 19:00
-
-
Save wernersmit/1ab5b23f803aca3558ee969b9d7824d9 to your computer and use it in GitHub Desktop.
Control visibility of WordPress menu items using if-menu plugin and custom conditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Filter below adds custom condition for IF-Menu plugin. | |
| * https://wordpress.org/plugins/if-menu/ | |
| */ | |
| add_filter( 'if_menu_conditions', 'pgs_menu_conditions' ); | |
| function pgs_menu_conditions( $conditions ) { | |
| $conditions[] = array( | |
| 'name' => 'Get URL Allowed', // name of the condition | |
| 'condition' => function($item) { // callback - must return TRUE or FALSE | |
| $allowed[] = '/residential/'; | |
| if (in_array($_SERVER['REQUEST_URI'], $allowed)) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| ); | |
| return $conditions; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment