To exclude specific pages from the admin pages list in WordPress based on their ID, you can use the pre_get_posts hook and modify the query parameters.
Here’s an example code snippet:
/**
* Snippet Name: Exclude Pages From The Admin Pages List By ID
* Snippet Author: https://wpproblog.com
*/
//To Exclude Pages From The Admin Pages List By ID
add_action( 'pre_get_posts' ,'exclude_this_page' );
function exclude_this_page( $query ) {
if( !is_admin() )
return $query;
global $pagenow;
if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
$query->set( 'post__not_in', array(1,2,3) ); // Replace with your desired page IDs
return $query;
}
Replace the array(1, 2, 3) with an array of the page IDs you want to exclude. You can add as many page IDs as needed.
Add this code to your theme’s functions.php file or in a custom plugin. After saving the changes, the specified pages will be excluded from the admin pages list in the WordPress dashboard.
Leave a Review