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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.