Excluding a page with a certain name from wp_page_menu

A client of mine has a WP multisite network of sites which all use the same template. This template uses wp_page_menu. I just added a mobile version of the template by using a certain plugin. It will use the same pages as the desktop version of the website, but the client has requested a different landing page.

The problem is that if I create a new page to facilitate this landing page, it will show up in the code generated by wp_page_menu. Since all sites in this network uses the same template and the page will have different page IDs on different sites, I cannot exclude it manually in the wp_page_menu function.

Read More

I was thinking that if I could exclude the post by title or category name instead of by ID, this might work. But I don’t know how to do that. Please help?

Related posts

Leave a Reply

1 comment

  1. How about using get_page_by_path(), then using the ID from the returned object in an exclude filter?

    add_filter('wp_page_menu_args','my_nav_exclude_pages');
    
    function my_nav_exclude_pages( $args = array() ) {
      $homepage = get_page_by_path('my-page-slug');
      $args['exclude'] = join( ',', array( $args['exclude'], $homepage->ID ) ); 
    
      return $args;
    }