Forums

preg_replace question (5 posts)

  1. cognitions
    Member
    Posted 2 months ago #

    I would like to exclude some pages from my wp_pages menu. But I need to exclude pages by title.

    I came across something very close to what I need below.

    function categories_without_title_attribute() {
    $categories = wp_list_categories('echo=0');
    $categories = preg_replace('/title=\"(.*?)\"/','',$categories);
    echo $categories;
    }

    It provides a function to call pages without the title attribute.
    What I need is to amend it so I can exclude pages that have specific titles. For example, let's say 'About Us' and 'Privacy Policy'.

    I have tried many variations but no effect. A number ofpeople have asked for this solution but there is nothing that works posted yet.

    ANy preg_replace experts have a solution that could build on the above function?

    Many thanks

  2. hallsofmontezuma
    Member
    Posted 2 months ago #

    It would be better if you exclude by id unless there is a compelling reason otherwise to make an exception.
    http://codex.wordpress.org/Template_Tags/wp_list_pages#Exclude_Pages_from_List

  3. cognitions
    Member
    Posted 2 months ago #

    Cannot exclude by Id because the page is created dynamically. The title is fixed but the name (slug) and id will vary.

  4. hallsofmontezuma
    Member
    Posted 2 months ago #

    $page = get_page_by_title('Page Title');
    echo $page->ID;

  5. cognitions
    Member
    Posted 1 month ago #

    Many thanks! Perfect. Sorry for the delay in thanking. Gave up :)

Reply

You must log in to post.

About this Topic