This Is An Original Unique WordPress Theme-Hack Devised By Shazzalive.
Shazzalive advises you to back up your WordPress files and folders before you embark on this; then if you do make a cock-up and end up wrecking a file for some unexplained reason; you can simply replace it from backup.
There may be an instance with your (self-hosted) WordPress blog, where you’d like to temporarily withdraw a page from viewing. Maybe you’d like to do so permanently even.
The trouble with simply deleting the page is that all the search-engines are displaying the URL of it, and going through the routine of informing them all that the page has been removed and waiting for them to remove its listing is a load of hassle and wastes time that could otherwise be used more productively.
Even if all the search-engines remove the URL; there’s still a good chance that people have it bookmarked in their browser: When they go to refer to it later they get either your 404 page or a server error maybe. – That doesn’t look all that professional; I think you’d agree.
What’s needed is a placeholder; (Is that the right terminology? – I’m going to use it for the purpose of this article regardless.) a notification that the page has been (temporarily) removed. You could delete the posts totally and design in such a placeholder. – Some text saying “This page is (temporarily) unavailable”, perhaps; but once again, it’s all hassle which uses up your time in which you could be doing something much more productive.
- Wouldn’t it be great if there were a button somewhere within the WordPress GUI that you could just click and the page in question instantly shows as unavailable, or displays a pre-assigned message on it rather than the original page’s content? That would save a heck of a lot of time and hassle, yeah? – all with a single click
.
Well the good news is that something very similar can be accomplished, and there’s no need to make any changes to the WordPress core: This hack is all done in your current theme’s folder, and there is very little chance of anything going tits-up, even if you do make a total pig’s ear of it.
Good ol’ genius Shazzalive to the rescue then.
Let’s talk about how we’re going to accomplish this: -
Let’s look at the structure of a page before we do anything else: Usually there are three, maybe four, main sections involved.
How the existing template structure works
The sections mentioned above start with the header: The header is always called first from the page template by the php, followed by whatever else in the way of templates. When the header has appeared; the php on the page template runs on the server, and then calls first the sidebar if there is a sidebar used with that particular template, and then after the sidebar’s appeared – if there is a sidebar called – it then calls the footer… And the footer appears…
More
So, if there were no page template, then the page in question wouldn’t appear. – But then neither would there be anything to call the header, footer, etc; and nothing at all would display.
The page template – as an actual object – itself doesn’t call the (sidebar and) footer: The php code on the page template is what calls the (sidebar and) footer. Likewise, the php content of the page template is what causes the pages’ content to be displayed. – Ordinarily that’s a good thing, but in this case we don’t want the page’s content t0 be displayed. – so, in order to accomplish our goal, we need to remove the php that displays the page’s’ content from the page template, but not the php that calls the (sidebar and) footer. – If we could do that then only the header and (sidebar and) footer would appear: The page’s content wouldn’t. = Target neutralised. ![]()
“- Just one goddam cotton-pickin’ minute there…” You’ve seen the flaw in that planning already haven’t you? – Doing that will mean that no pages are displayed. – None of them.
– What we could do with is another page template; a second page template in other words. Allow me to explain why: -
‘See if we could, under normal circumstances – e.g. for all pages that we want displayed normally – , use the standard page template, but have a second page template as described above that we could call in the case where we didn’t want the pages’ content displayed, then we’d be in clover, problem solved!
Now here I’m thinking that the editor in the WordPress UI does actually give us a choice of templates to use for an individual page; so that’ is as good a way as any of selecting an alternative template.
Let’s make an alternative page template: -
OK; so we first of all want a second page template. – Where is the best place to find a second page template?
Answer = The original page template.
“But there’s only one of those.” you interject.
Not if we copy it: Then there are two. Two identical page templates, but nevertheless two of them. We can change the “identical” thing forthwith: Let’s just get the second one created first.
(Maybe there is more than one available page template in your theme; but I’m assuming there’s only one. If there are more than one it makes no difference; we still need to create one more. – Read on… )
OK to copy a page template: We can’t really do it while in WordPress can we? – So first things first: We need an experimental area on our local machine’s hard-drive to work in: -
Workspace
On the Desktop create a folder called “php lab”. I have mine – and it’s already in use for a number of projects; but you need one too. – So do that. Now we need to retrieve a copy of your blog’s current theme: Open up your ftp client, (I use FileZilla 64-bit. (Because I have a 64-bit operating system. – But it doesn’t matter whether you have a 64-bit or a 32-bit operating system. (If you want to use FileZilla then there is both a 32-bit and a 64-bit version available which works with Linux and with Windows. I’m not sure if there is one that works with Mac though: I don’t think there is at time of writing.)) Copy the theme folders and files of the theme you’re currently using to a folder in the “php lab” folder on your desktop.
(To get to your blogs’ available themes files you’ll need to go to the root folder of your web-space, in which you should see the WordPress core folders. (WP-admin, WP-includes, WP-content, etc.) You want to open the folder WP-content, or the equivalent thereof if you’re security-conscious and have changed the prefix, in which you will see a folder titled “themes”: Open that, find the folder with the name of your current theme and download it to the folder “php lab” on your desktop.)
Tools
Next: There should be a file in the copy of your current theme’s folder called “page.php”. We need to open it. To do this we either need the default Notepad program that ships with Windows, (Or the Linux or Mac equivalent if you’re using Linux or a Mac.) – Or better still, a nice program called Notepad++. (I think it’s available for Linux and Mac in addition to Windows.) Google it and install it if you don’t have it installed and you want to do more coding of any kind: It’ll be most useful to you in the future.
When you click on the file “page.php”, you may find, if you’ve never opened a php file before, that your computer doesn’t have a clue what to open it with and asks you to tell it what to open it with. Associate php files with either Notepad++, if you have it installed, or Notepad if you don’t and don’t want to install… – Oh you know what I mean lol
_.
Begin
OK open the file page.php. Inside it, as its’ suffix suggests, you’ll see a load of php. This is a copy-file though, and this file is going to end up as our second page template. – Bear with me here – Most of the php in the original file is surplus to requirements, because we don’t want the new page template to display the contents of the page. – Displaying the contents of the page is what most of all that php is for. – Therefore we can remove most of that php… Later : -
First though: -
At the very top of the file you’ll see some php that looks similar to this: -
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other ‘pages’ on your WordPress site will use a
* different template.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
The text-part of this may be totally different in the theme that you are using; but whatever the case, you want the top line that starts with <?php right down to */ . That piece of php is identifying the file to WordPress as page.php. We already have page.php existing in the real in-use directory back on the web-space; so if we’re going to copy this back to the same folder when we’ve hacked it up, the last thing we want is for WordPress to recognise this folder as another page.php because WordPress isn’t clever enough to understand the notion of two files with the same name. – Vous comprondez? – So we are going to have to change that piece of php.
Hack it
Let’s change things a bit, to make WordPress think that the file is called “deleted_template.php”: Delete the previous php shown above and add the following in its place. DO NOT remove the line “get_header(); ?>” : -
<?php /* Template Name: deleted_template */
Now WordPress will see that file as another template.
In fact – let’s change the name of the file properly; since WordPress is gonna call it by another name we’ll do the same: Rename the file to deleted_template.php .
- There we go: WordPress will now see that file as deleted_template.php and so will we: Because the file is now called deleted_template.php and even the computer agrees. – ‘Cool as a cucumber. ![]()
Feel free to take a break at any time if you think this is going on a bit long. Go have a cuppa, and a ciggy if you smoke, and then come on back to this and we’ll press on.
Hack it some more
OK; so far so good: we’ve got two different page templates which both we and WordPress will recognise as such. Now we want to make the template that we created; namely deleted_template.php, do what we want it to do.
As I said earlier on; most of the php in the page template is displaying the page… and the comment-area, blah blah. – So if we remove the php that is causing the page to display we’ll have only the header + the (sidebar and) footer displayed when any page, no matter what its content, uses that template. – Therefore; open up deleted_template.php and remove everything but the piece of php that we’ve just added that identifies the template to WordPress, leaving only that, the opening get_header(); ?> immediately following it that closes the php statement, and the final ( <?php get_sidebar(); ?> and ) <?php get_footer(); ?> lines.
The file should now be rather empty of php content and should read like this: -
<?php
/*
Template Name: deleted_template
*/
get_header(); ?>
<?php get_footer(); ?>
( You might also have a line that reads like this: <?php get_sidebar(); ?> In my honest opinion you may as well remove that too; as a sidebar will look odd with no page content. )
If we were to use this code in the new template inside WordPress as it is, in conjunction with a page, then it would not display the page content; but rather would display only the header and the footer, and that’s exactly what we want. – Also – We need a bit of text between the header and the footer to make it look as if there used to be something there; I.O.W tell the readers that the page has been removed: -
Add HTML
Add something like the HTML line that I’ve added in the following example. – Put whatever content you prefer in it; I’ve just added what I want to use in the example. I’ve colour-coded it with an explanation of what does what for those of us who are not familiar with HTML coding: -
<?php
/*
Template Name: deleted_template
*/
get_header(); ?>
<p align=”center”><h2 align=”center”><strong>This page has been deleted by the blog’s owner for some reason.</strong></h2></p>
<?php get_footer(); ?>
Key: -
The HTML in purple is the opening and closing paragraph-tags. You’ll notice that the opening tag aligns the text to the centre of screen. – <p align=”center”></p> (There is no need to close the alignment as the closing </p> tag does this also.)
The HTML in red is the header2 opening and closing tags. Again the alignment is to the centre of screen. – <h2 align=”center”></h2> (There is no need to close the alignment as the closing </h2> tag does this also.)
The HTML in blue is the opening and closing tag to produce bold type. – <strong></strong>
The text in brown is just that: Text. Because it is not between angled brackets thus <>, the computer reading it doesn’t treat it as HTML but rather as text to be printed on the screen.
I hope my explanation of this HTML was clear enough to anyone not in the know.
We’ve almost finished; so save your work and close the file deleted_template.php . Use your FTP client to upload it to the same location on your server in the current themes’ folder; that is yourdomain/wp-content/themes/yourcurrenttheme/deleted_template.php. That’s got that bit done: Now we can close the FTP client because we won’t be needing it any more for this operation. I suggest that you keep the folder “php lab” on your local machine. It may well come in handy at a later date; and it’s only taking up a few kilobytes.
The good news is that we’ve nearly finished. – ‘Only a few more things to do now: -
…And Finally: -
Go into your WordPress Admin page and click on the pages tab in the sidebar on the left. Open an existing page for editing; any page, but preferably a page that you’re not too fussed about. In the section “Page Attributes” in the sidebar on the right, click the arrow to release the drop-down list of templates. You’ll see deleted_template in the list. Select it as the template associated with that particular page and that particular page will no longer show. Anyone browsing to that page will see only the header and the (sidebar and the) footer. They will also see the text part of the HTML you added between the header and the footer. In the case of my own file’s displayed HTML it says: -
This page has been deleted by the blog’s owner for some reason.
The page itself hasn’t been altered in any way; it’s just not showing, and the message that you added to the template that you just created is showing. Any time that you want the page to display again as normal, simply associate the other – or any of the other; if you’ve created more or there were more than one to begin with, templates with it. (I’ve just been through how to create new page templates, so now you can create as many as you like.) You can now cause any of the existing pages to vanish and show a notice that they’ve been suspended from view; just by selecting the deleted_template template from the “Page Attributes” section of the page’s individual edit-panel in the WordPress UI.
- It’s easy when you know how, eh?
Shazzalive is alive and thrives.
-
Can YOU create an original WordPress hack and test it to ensure that it works? If you can then I’d like to publish it on this blog. – So do send it in within an article for publication. – Use the “Write for Kkomp.com-Beyond” link. – I’ll link back to your website, give you all the credit with a short editorial prologue, and put your creation on the map in social-media such as Twitter and Facebook with links back to your article. I look forwards to hearing from my resourceful readers.
WordPress is just so incredibly versatile. There is no end to the number of ideas and hacks that one can create with it!
“Kind’a” Copyright ( – ?)
I think this is my original idea: I’ve certainly never seen it online before; and as far as I’m aware, nobody else has come up with it yet. I’m claiming it as my own anyway. If anybody wants to dispute that then please contact me using the form below.
I’m not saying that you can’t use this idea on your own blog, of course. Heck I’m showing you how you can do it yourself: To try to stop you from doing so would be going against the spirit of the freedom of WordPress. – So please don’t think that I’m stopping you from doing likewise to me, or telling your friends how to do it, or whatever. All I’m saying is that I want to be known as the person from whom the idea originated.
There is more coming up soon; but for now – well it took me quite a while to compile this post; so now, if you don’t mind, I’d like to make viewing all the adverts compulsory for you, as my reward…
Stay geeky.
This article is also available in .pdf format. Download the .pdf here.
You’re looking at Kkomp.com – Beyond. <--Link to Home page.
The URL of what you see is http://kkomp.com/2011/11/25/how-to-temporarily-suspend-a-pages-viewing-in-wordpress/
Why not share the linked URL by pasting it into Facebook or sending it by email?
Post Footer automatically generated by wp-posturl plugin for wordpress.
















Wow Shazzalive, pretty useful tutorial and in fact quite nicely explained. In fact I am total noob at WordPress editing but you made it so easily followable that even a starter could understand. Hats Off! I could make use of this for some stuff. I think Many themes comes with inbuilt page templates but I never thought it was so easy to make one ourself and use if for showing these kind of messages.
Shiva @ Blogging Tips recently posted..Commentluv Premium Review – Why I Opted For It
As I stated in the article itself; the great thing about WordPress is it versatility. All that’s needed is a basic understanding of php and some HTML editing skills. – With them you can customise the heck out of your installation, and some; particularly with regard to the theme.
Thanks for the kind compliments too.
Pingback: Build A Custom Home Page For Your WordPress Blog | Kkomp.com - Beyond
Pingback: Use Your WordPress Self-Hosted Blog as a php Test-bed | Kkomp.com - Beyond