Hiding Pages with Wordpress part 2 – Errors, Omissions, and Solutions
byIn a previous post, how to hide pages in wordpress, I talked about hiding pages in wordpress. I gave three solutions, one was wrong
and the others were a little confusing. I could have sworn that the draft and private methods worked...maybe they were bugs in older versions? I want to thank a reader from blogsandbucks.com for pointing out that the draft method for hiding pages does not work.
if you make a page, and save it as a draft, you will be able to access it but only if you are logged in. I guess made a page and didn't logout to see how the write would look from.
adding exclude='' and include='' should still work, even for WP2.2...I'm looking into it.
- exclude (string)
- Define a comma-separated list of Page IDs to be excluded from the list (example: 'exclude=3,7,31'). There is no default value. See the Exclude Pages from List example below.
- include (string)
- Only include certain Pages in the list generated by wp_list_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. There is no default value.
I also want to thank, blogsandbucks for pointing me to the code section in the post-template.php file. Since a lot of people are having trouble with hiding pages from the menu and sidebars, I wrote a little script which adds checkboxes next to the pages in the admin section so you can easily hide pages.

Warning, this is geeky...you will be editing 3 files...if you are scared, shoot me an email and I'll take care of you.
You can download the altered pages here: hide_pages.zip - for wp 2.2 only...but it might work with earlier versions.
first, we have to update the blog options to store an array of our hidden pages.
open wp-admin/admin-functions.php
You have to add the checkboxes to the table.
There is a function around line 830: page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true )
this function lists the pages in the admin section. You need to add a table row.
add this to the '<tr>' block...you should make it the last '<td>' section
-
<?php $hidden_pages = get_option('hidden_pages'); ?>
-
<td align="center"><?php echo (in_array($id, (array)$hidden_pages)) ? "<input name='page_hide[]' type='checkbox' value=$id checked='checked' />" : "<input name='page_hide[]' type='checkbox' value=$id />" ; ?></td>
That code will add checkboxes to your admin pages section. you are done with this file. Save and upload to your website.
now open wp-admin/edit-pages.php
You have to wrap the table that lists the pages in a form. so you are going to add form tags around line 34.
-
<!--add these form tags-->
-
<form action="" method="post">
-
<table class="widefat">
-
<thead>
-
<tr>
-
<th scope="col" style="text-align: center"><?php _e('ID') ?></th>
-
<th scope="col"><?php _e('Title') ?></th>
-
<th scope="col"><?php _e('Owner') ?></th>
-
<th scope="col"><?php _e('Updated') ?></th>
-
<th scope="col" colspan="3" style="text-align: center"><?php _e('Action'); ?></th>
-
<th scope="col" style="text-align: center"><?php _e('Hidden') ?></th>
-
</tr>
-
</thead>
-
<tbody id="the-list">
-
<?php
-
page_rows(0, 0, $posts, $all);
-
?>
-
</tbody>
-
</table>
-
<!--add the closing form tags-->
-
<p class="submit"><input name="update_pages" type="submit" value="Update Visiblity" /></p>
-
</form>
this will send an array of hidden pages as post data to get inserted into the blog options.
Then right after "require_once('admin-header.php');" on line 6 of the same page add this code:
-
if(isset($_POST['update_pages']))
-
{
-
$hidden = $_POST['page_hide'];
-
update_option('hidden_pages', $hidden);
-
}
That will do the insert. you might need to serialize the $hidden variable before you update_option. I think on newer versions of WP, update_option will serialize arrays for you.
you are done with edit-pages.php. Save and upload to website
Now open wp-includes/post-template.php
This is the page that controls the layout visible by the public. you will find a function called wp_list_pages($args = '') around line 277. a few lines after that you will see all the arguments you can send that function, one of which is exclude=''. right after this line: $r = array_merge($defaults, $r);
add this code:
-
if(get_option('hidden_pages')!='')
-
{
-
$r['exclude'] = implode(",", get_option('hidden_pages'));
-
}
that just reads your blog options and then makes a string of page id's to exclude.
this is licensed under the WOMC (worked on my computer), so if you have any questions feel free to shoot an email.
Popularity: 17% [?]