Support » Fixing WordPress » How to exclude a page from navigation by title or slug

  • Resolved cognitions

    (@cognitions)


    Is there a way to exclude a page from wp_list_pages by Page Title or Page Slug. I cannot know the ID in advance so i cannot use

    wp_list_pages(‘exclude=3’)

    I am trying to get this to work:

    wp_list_pages(get_page_link(get_page_by_title(‘Publish Post’)->ID))

    but I cannot.

    Many thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • $page = get_page_by_title('About');
    wp_list_pages('exclude='.$page->ID);
    Thread Starter cognitions

    (@cognitions)

    Thankyou. It works, but I forgot to mention that there is more than one page to exclude.

    I have studied the codex to see how to put them in an array but no luck.

    So far I have this:

    $page = get_page_by_title (array(
    'About'),
    ('Privacy'),
    ('Disclaimer')
    ));

    But it only excludes the first page ‘About’.

    Thank you.

    You’d have to get each value individually.

    Thread Starter cognitions

    (@cognitions)

    OK. I have got the values individually like this:

    $page1 = get_page_by_title ('About');
    $page2 = get_page_by_title ('Services');
    $page2 = get_page_by_title ('Privacy');

    and they all work. For example:

    wp_list_pages('exclude='.$page1->ID);
    wp_list_pages('exclude='.$page2->ID);
    wp_list_pages('exclude='.$page3->ID);

    But I cannot seem to combine them so that a single instance of wp_list_pages excludes all of them.

    I know this is no where near right, but the result I am seeking is:

    wp_list_pages('exclude='.$page1->ID, .$page2->ID, .$page3->ID);

    Thanks for your help so far. Sorry not to have figured this.

    $args = 'exclude=' . $page1->ID . ',' . $page2->ID . ',' . $page3->ID
    wp_list_pages($args);
    Thread Starter cognitions

    (@cognitions)

    Thank you!

    For others seeking this solution (provided by MichaelH):-

    The code for excluding pages when you know the Title but not the ID. The following is an example excluding three pages from the menu.

    <?php
    $page1 = get_page_by_title ('About');
    $page2 = get_page_by_title ('Services');
    $page3 = get_page_by_title ('Privacy Policy');
    
    wp_list_pages('exclude=' . $page1->ID . ',' . $page2->ID . ',' . $page3->ID);
    ?>

    thanks it working ……… but can any one help it by using array

    oldboygla

    (@oldboygla)

    Is there any way to make it so that when you exclude a page it also excludes all the sub-pages under it? Rather than having to put the sub-pages in manually?

    cdk1212

    (@cdk1212)

    Hi,
    I have a question related to excluding pages from nav bar but not excluding from page source. Because all the exclude option does is make the page private and I don’t want the page to be private

    any suggestions

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to exclude a page from navigation by title or slug’ is closed to new replies.