3

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

1 Answer 1

7

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;
 }
4
  • If you globalise $post_type you'd not need to reference $_GET to check the post type(it does get reliably set for admin pages - unlike $typenow).
    – t31os
    Commented Mar 30, 2011 at 21:42
  • @t31os: Thanks for the tip, i updated the code.
    – Bainternet
    Commented Mar 30, 2011 at 21:46
  • @Bainternet: Thanks for the nice bit of code. But the problem is: anything that is applicable for any lower roles, is also applicable for upper roles too. I added && current_user_can( 'edit_posts' ) to your code-snippet, but it's hiding pages from Admin role too. :( I want to hide pages only from the sight of Editor, none other. How can I? Commented Aug 1, 2013 at 9:16
  • Ok, got the solution: && current_user_can( 'editor' ). current_user_can() also takes Admin role. :) Commented Aug 1, 2013 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.