Hide a page in the admin end without a plugin?

I’m creating a series of pages with iFrames embedded in them, but it seems the only way to do this within WordPress (i.e. using the templating system) is to create pages in the admin end and then create individual templates for each of those pages.

Is it possible to hide those pages from the admin without a plugin? I see no need for the client to see those pages when they can’t edit anything in them.

Thanks,

osu

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

you can use parse_query filter hook to exclude your pages using post__not_in attribute

add_filter( 'parse_query', 'exclude_pages_from_admin' );
function exclude_pages_from_admin($query) {
    global $pagenow,$post_type;
    if (is_admin() && $pagenow=='edit.php' && $post_type =='page') {
        $query->query_vars['post__not_in'] = array('21','22','23');
    }
}

this will exclude pages with the ids of 21,22,23

and to make sure this pages will not be included on the front end using wp_list_pages
you can use wp_list_pages_excludes filter hook:

 add_filter('wp_list_pages_excludes', 'exclude_from_wp_list_pages');
 function exclude_from_wp_list_pages($exclude_array){
    $exclude_array = $exclude_array + array('21','22','23');
    return $exclude_array;
 }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x