Skip to content

Instantly share code, notes, and snippets.

@wernersmit
Created October 17, 2018 19:00
Show Gist options
  • Select an option

  • Save wernersmit/1ab5b23f803aca3558ee969b9d7824d9 to your computer and use it in GitHub Desktop.

Select an option

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
<?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