Jump to content

How to unpublish a page without deleting it?


ryan
 Share

Recommended Posts

This article introduces multiple concepts in ProcessWire, as goes far beyond the stated subject. The subject of "unpublishing a page" serves as an ideal context, so I encourage you to read the entire article (particularly strategy #2) as it introduces the concepts of role inheritance and API-level page access, among other things.  

To unpublish a page without permanently deleting it, use any one of the following 4 strategies (whatever suits your needs best).

STRATEGY #1: MOVE THE PAGE TO THE TRASH


This is the most straightforward strategy, but does involve moving the page. I don't permanently delete pages very often, so I use the trash as more of an archive. When you delete a page in the ProcessWire admin, it just moves the page to the Trash. You can still move it back out at any time (as long as you haven't emptied it first). Pages in the trash are not web accessible and don't appear in search results, so it's a good place to unpublish your page.

To unpublish your page in this manner, just delete it by clicking it's 'delete' tab, checking the confirmation box, and saving it. The page will be waiting for you in the trash.

You can also trash pages directly in the Page List view:

1. Go to the Page List view by clicking "Pages" in the top right corner.

2. Click the Trash page to open it.

3. Click the page you want to unpublish, you should see a 'move' link.

4. Click the 'move' link, and then drag the page into the trash.

From the API you can trash pages by calling $pages->trash($page);

STRATEGY #2: REMOVE THE GUEST ROLE FROM THE PAGE:


This strategy includes a few factors to consider, but has the benefit of not having to move the page. First off, here's how you do it:

1. Edit the page and click on it's 'Settings' tab.

2. Locate the 'Roles' section near the bottom.

3. Uncheck the 'guest' role.

4. Consider checking the 'hidden' status too (see the section further down).

4. Save.

The 'guest' role implies anonymous site users. If there are any other roles still checked, those are the only roles that can view the page. If no roles are checked, then only the 'superuser' role can view the page.

Note that the page can still appear in API function results (like in your navigation), so you should also check the 'hidden' status too if you don't want that (see section further down) OR check access in the API (see the API section further down).

Note about Role Inheritance

This note is only applicable to a Page that has children. Page roles are inherited through the site tree, so unchecking a 'guest' role on /about/company/ unchecks it on any children and grandchildren, and so on. For example, if you removed the 'guest' role from /about/company/, then these page would also be inaccessible to 'guest':

/about/company/staff/

/about/company/staff/mike/

But you can still turn the 'guest' role (or any other role) back ON at any of the descending pages. For instance, you could turn the 'guest' role back on at /about/company/staff/ and that page would be accessible, even if it's parent isn't. Because roles are inherited, enabling 'guest' at /about/company/staff/ also enables it for /about/company/staff/mike/, but the same rules about inheritance apply no matter where you are in the site structure. As a result, removing the 'guest' role from the homepage would unpublish the entire site from public access, unless any other pages had specifically set a different behavior.

Note about Roles and the API

In the ProcessWire API, the results of any page selection functions like get(), find(), children() and siblings() do not consider roles. If the page is in your site tree, you can still select it in the API. This is so that you can continue to use assets from a page in the API even if the page isn't a URL on your site. 'Page' is just an abstract term that doesn't have to refer to a page on your site... You might be using a page for storage of shared image assets, site configuration or other items that you don't want to be directly accessible via a URL, but you DO want to utilize in the API.

As a result, if you don't want a page showing up in navigation or search results you can do one of 2 things:

1. Check the box for the 'hidden' status (described in the section further down).

2. Or, when generating your navigation, check if the page is viewable before outputting the link via $page->isViewable(). For example:

<?php
foreach($page->children() as $child) {
   if($child->isViewable()) echo "<a href='{$child->url'}'>{$child->title}</a> ";
}

I don't like having to check access from the API, so recommend doing #1 over #2. In the near future, automatic access checking will be an option you can optionally enable with API functions (should you want to).

STRATEGY #3: USE THE HIDDEN STATUS


Another alternative to unpublishing (via removing the 'guest' role) is to enable the 'hidden' status in the page editor. You may want to use this instead of–or in addition to–removing the 'guest' role, depending on your needs. This strategy doesn't technically unpublish the page unless you combine it with strategy #2. But this strategy is often a better solution then just unpublishing, as there is no danger of breaking any on-or-off site links.

1. Edit the page you want to hide and click on it's 'Settings' tab.

2. Locate the 'Status' section.

3. Check the box for 'Hidden'.

4. Save.

A hidden page is excluded from the API find(), children() and siblings() results, which essentially excludes it from any of your dynamically generated navigation. It's not excluded from get() results, so the page can still be accessed by it's URL or loaded individually from the API. This means the page isn't going to show up in your navigation or search results, but loading the URL directly will still load the page.

STRATEGY #4: JUST DON'T DO IT (IF YOU DON'T HAVE TO)


As a best practice, I always encourage my clients not to delete or unpublish pages if they don't have to. For example, let old news items drift further down the list rather than deleting them... someone, somewhere may be linking to it. Every link to your site carries value, even if the page being linked to isn't recent. At least the user gets what they expected and can explore further in your site. And Google will still count that link as a vote in favor of your pagerank. Delivering a 404 page is less likely to result in that outcome for the user or your site. Of course, there are lots of good reasons to delete or unpublish a page, so I'm just speaking about the situations where you don't necessarily have to delete it.

Another alternative is to setup 301 redirects for pages that you delete or unpublish, but I won't cover that here unless someone wants me to.

Link to comment
Share on other sites

  • 5 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...