Title: preg_replace question
Last modified: August 19, 2016

---

# preg_replace question

 *  [cognitions](https://wordpress.org/support/users/cognitions/)
 * (@cognitions)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/preg_replace-question/)
 * 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

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Michael Torbert](https://wordpress.org/support/users/hallsofmontezuma/)
 * (@hallsofmontezuma)
 * WordPress Virtuoso
 * [16 years, 6 months ago](https://wordpress.org/support/topic/preg_replace-question/#post-1208869)
 * 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](http://codex.wordpress.org/Template_Tags/wp_list_pages#Exclude_Pages_from_List)
 *  Thread Starter [cognitions](https://wordpress.org/support/users/cognitions/)
 * (@cognitions)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/preg_replace-question/#post-1209109)
 * Cannot exclude by Id because the page is created dynamically. The title is fixed
   but the name (slug) and id will vary.
 *  [Michael Torbert](https://wordpress.org/support/users/hallsofmontezuma/)
 * (@hallsofmontezuma)
 * WordPress Virtuoso
 * [16 years, 6 months ago](https://wordpress.org/support/topic/preg_replace-question/#post-1209141)
 * $page = get_page_by_title(‘Page Title’);
    echo $page->ID;
 *  Thread Starter [cognitions](https://wordpress.org/support/users/cognitions/)
 * (@cognitions)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/preg_replace-question/#post-1209186)
 * Many thanks! Perfect. Sorry for the delay in thanking. Gave up 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘preg_replace question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [cognitions](https://wordpress.org/support/users/cognitions/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/preg_replace-question/#post-1209186)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
