# Pages Widget: Exclude Pages and Sort by Menu Order

> Hides pages such as Privacy Policy or Thank You from the Pages widget and sorts the rest by their menu order.

- Type: PHP
- Runs: Run everywhere
- Category: [Widgets](https://wpide.com/library/category/widgets/)
- Tags: widgets, pages, navigation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pages-widget-options/

## Code

```php
// Page IDs to hide from the Pages widget.
$wpide_pages_widget_exclude = array( 0 );

add_filter( 'widget_pages_args', function ( $args ) use ( $wpide_pages_widget_exclude ) {
    $existing = isset( $args['exclude'] ) ? wp_parse_id_list( $args['exclude'] ) : array();

    $args['exclude']     = implode( ',', array_merge( $existing, array_map( 'absint', $wpide_pages_widget_exclude ) ) );
    $args['sort_column'] = 'menu_order, post_title';

    return $args;
} );
```

## Notes

Use page IDs.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Pages Widget: Exclude Pages and Sort by Menu Order" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
