Skip to main content
added 1 character in body
Source Link
chrisguitarguy
  • 21.5k
  • 5
  • 62
  • 99

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter( 'wp_nav_menu_objects', function( array $items, arrayobject $args ) {

    if ( 'someThemeLocation' !== $args->theme_location ) {
        return $items;
    }

    return array_filter( $items, function( $item ) {
        return '/user-specific-thingy' === $item->url 
            && ! is_user_logged_in();
    } );

}, 10, 2 );

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter( 'wp_nav_menu_objects', function( array $items, array $args ) {

    if ( 'someThemeLocation' !== $args->theme_location ) {
        return $items;
    }

    return array_filter( $items, function( $item ) {
        return '/user-specific-thingy' === $item->url 
            && ! is_user_logged_in();
    } );

}, 10, 2 );

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter( 'wp_nav_menu_objects', function( array $items, object $args ) {

    if ( 'someThemeLocation' !== $args->theme_location ) {
        return $items;
    }

    return array_filter( $items, function( $item ) {
        return '/user-specific-thingy' === $item->url 
            && ! is_user_logged_in();
    } );

}, 10, 2 );
Simplified code as I just stumbled upon it
Source Link
kaiser
  • 50.8k
  • 27
  • 150
  • 244

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter('wp_nav_menu_objects', 'wpse233667_nav_menu_objects', 10'wp_nav_menu_objects', 2);
function wpse233667_nav_menu_objects( array $items, array $args )
  { 

    if ( 'someThemeLocation' !== $args->theme_location ) {
        return $items;
    }

  $out = [];
  foreachreturn array_filter( $items, asfunction( $item ) {
    if (   return '/user-specific-thingy' === $item->url && !is_user_logged_in()) {
      continue;
    }
  && ! $out[]is_user_logged_in();
 = $item;
  } );

}, 10, return2 $out;
});

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter('wp_nav_menu_objects', 'wpse233667_nav_menu_objects', 10, 2);
function wpse233667_nav_menu_objects($items, $args)
 {
  if ('someThemeLocation' !== $args->theme_location) {
    return $items;
  }

  $out = [];
  foreach ($items as $item) {
    if ('/user-specific-thingy' === $item->url && !is_user_logged_in()) {
      continue;
    }
    $out[] = $item;
  }

  return $out;
}

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter( 'wp_nav_menu_objects', function( array $items, array $args ) { 

    if ( 'someThemeLocation' !== $args->theme_location ) {
        return $items;
    }

    return array_filter( $items, function( $item ) {
        return '/user-specific-thingy' === $item->url 
            && ! is_user_logged_in();
    } );

}, 10, 2 );
Source Link
chrisguitarguy
  • 21.5k
  • 5
  • 62
  • 99

Filter wp_nav_menu_objects. It will contain the sorted list of nav menu items to render. Have a look at wp_setup_nav_menu_item for some properties you can use.

Here's a quick (untested) example.

add_filter('wp_nav_menu_objects', 'wpse233667_nav_menu_objects', 10, 2);
function wpse233667_nav_menu_objects($items, $args)
{
  if ('someThemeLocation' !== $args->theme_location) {
    return $items;
  }

  $out = [];
  foreach ($items as $item) {
    if ('/user-specific-thingy' === $item->url && !is_user_logged_in()) {
      continue;
    }
    $out[] = $item;
  }

  return $out;
}