Customizing the Error Page for Deactivated or Archived WordPress Sites
Customizing the Error Page for Deactivated or Archived WordPress Sites
If you run a WordPress Multisite network, the chances are that you’ve had to archive, suspend or delete one or two sites along the way.
If the network is for your own use, you may have created a site and then realised you don’t need it after all, you might have moved it to a standalone WordPress installation, or you could have accidentally created a duplicate of a site you’ve already created. I’ve done all of these – not too clever!
If the network is open for users to create their own sites, then you’ll have had to take down some spammy blogs over time, or maybe remove a site that someone set up under a free trial but didn’t continue with.
And if you’re using your network to host client sites, then you may have had a site that’s migrated to its own WordPress installation or that you’ve removed when the client has gone out of business or moved on to another web developer or host.
By default, if someone visits a site that you’ve deactivated, they’ll see a pretty dull default screen telling than that the site has been suspended.
But what if you want to customize this screen, or add some custom content such as a link encouraging people to visit your main site or create their own blog?
In this post, I’m going to show you exactly how to do just that. I’ll show you how to create a file in your wp-content directory that overrides the default file for that screen, and how to style it.
But before I do that, let’s look at the different options you have for suspending a site, and what users will see when you do each of these.
Suspending Sites in Your Network – the Options
I have to admit that I find the terminology around deleting and suspending sites in a network very confusing. It’s not entirely clear what each one means and sometimes when you do one, the system will tell you that you’ve done another.
So let’s have a recap on the options for removing sites from your network.
Here’s a detail of the Multisite Sites screen, which you access by going to My Sites > Network Admin > Sites:
There are four options for removing the site:
- Deactivate reverses the activation step users go through when they signup for a site. It doesn’t permanently delete the site which can be reactivated at any time. Neither the front end nor the site admin screens are accessible.
- Archive marks a site as being archived so it’s not accessible by users. The admin screens can be accessed but not the front end. Again, you can easily archive a site at any time and it hasn’t been removed.
- Spam doesn’t delete the site, but marks it as spam. It’ll be unavailable (front end and admin) until you decide to unmark it as spam or delete it.
- Delete deletes the site. Use this option with extreme caution!
The Default Screen for Suspended Sites
WordPress has a default screen that it displays when a site is removed.
Here’s what you see in each scenario.
If a site is deactivated and someone other than the (logged in) network admin visits it, they’ll see a default screen:
Archived Sites and Sites Marked as Spam
If you mark a site as spam or archive it, you’ll get a different screen:
These screens are very basic. They don’t really give the visitor much information or explain what’s meant by ‘no longer available’ or ‘archived or suspended’.
So let’s create our own.
Note that if the site has been deleted you won’t see one of these screens – instead you’ll be taken to a 404 page in the main site.
Creating a Page for Deactivated Sites
Creating a new page for displaying when someone visits a deactivated site is quite straightforward. You simply create a new file called blog-deleted.php and put it in your network’s wp-content folder. This file will then be used to display a custom page instead of the default page.
Note that this is in the network’s wp-content.php folder and so the same file will be used for any sites in your network that are deactivated. This means that you need to create something generic, rather than something specific to one site in your network.
Note: the title of this file is very confusing. It doesn’t apply to deleted sites, just to deactivated ones!
The page you create will need to stand alone – it won’t be using the site’s theme or calling any plugins or additional files. So you’ll need to either include any styling in that file or call an external stylesheet, which you would put in a styles folder in your wp-content folder.
You’ll also need to include the
<head> section and the opening and closing
<body> tags as these won’t be coming in via your theme’s header or footer files.
For the sake of simplicity I’m going to create a very simple file with all the styling included in it.
You can start with a completely blank file if you’d like or you can copy some of the content from your theme files. For one, I’ve copied in the contents of my theme’s header.php file and edited those down significantly, then manually added the rest of the markup.
1.6 million WordPress Superheroes read and trust our blog. Join them and get daily posts delivered to your inbox - free!
Here’s the contents of my
That gives me the required content plus some metadata and styling.
Now for the
There isn’t much to the body – just an element for the content, with a paragraph inside it and some text, which is translatable. This includes a link to the main site, which you might want to include if your network allows user sign-ups. Alternatively you might link to a different site on your network if this site has been replaced, or to a page on your main site explaining your policy for deleting sites, or wherever you wanted.
Let’s take a look at the screen we get now if a site is deactivated:
It isn’t very pretty right now – you might want to add some different styling, colours and maybe a headline. But it shows you that it’s possible to replace the default page for deleted sites and add anything you want to it.
Creating a Page for Archived Sites
If you want to also create a custom page for sites which have been archived or marked as spam (and why wouldn’t you?), you’ll need to create another file, also in your wp-content folder. This is called blog-suspended.php.
I’ve created another file which is identical to my blog-deleted.php file but with slightly different text. Here’s the code:
Here’s the page you get when you visit an archived site:
So again, our visitor has some more information and a link to the main site. You can replace this with whatever you want.
More Advanced Options
You can take this technique further.
The first thing you can do to improve your code is to separate out the styles and add them to a stylesheet in your wp-content folder. You’d then call that stylesheet from each of the two files for suspended and deactivated sites, meaning you only need to code the styling once. If you want different styling for each of the two pages, you can add an extra class to the
body tag for each file and target that.
To call your new stylesheet, add this line of code to the
<head> section of your file:
Alternatively you could import the stylesheet from the theme which has been activated for the suspended site. Be wary of doing this – if the site is spammy, there may be a problem with the code, or you may have removed the theme altogether after deactivating the site. But if you want to do this, you can include the theme stylesheet with this line in the
You could take this even further by using the
include function to call specific files from the theme such as the header or footer. But again, be wary, as the theme may be deleted or corrupted. If you do this, it gives you the option of giving each blog a suspended page that looks unique.
Another option is to use the stylesheet from your main site, meaning you can brand all of your suspended/deactivated screens with your own branding. To call the stylesheet from the main theme, you’d need to add this code in the
You’d then use the appropriate elements for the markup in your page so that it works with your main blog’s theme – or you could call files from that theme using the
Finally, you could use conditional tags to check on the blog ID, the status of the blog, or anything else you’d like to check for, and then serve up content accordingly.
But if you don’t want to go this far, a simple page like the one we’ve created above will provide visitors with more information than the default, and lets you direct people elsewhere in your network.
It’s Easy to Replace the Default Pages for Deactivated Sites
If you follow the steps above, you can quickly and easy replace the default pages for archived, suspended or deleted sites in your network.
This way you can give visitors more information than that provided by the default screens, and give them a link to your main site so they don’t just leave your network entirely.