Create Blank Page for Wordpress Blog Using Your Theme Template

Posted: July 8th, 2009 | Author: jriggs | Filed under: php, wordpress | 5 Comments »

There may come a time when you need to create a blank page on your Wordpress site that still uses your template’s header, footer and sidebar.  For example, if you incorporate your own custom search from google, you will need to specify a landing page where the search results will be displayed.

You could use Wordpress to create a new page, but this has some problems.wordpress logo

  • Wordpress tends to add code to the page the you don’t need or want
  • You will need to recreate this file whenever you switch themes or upgrade.
  • You cannot easily control where this file is created.

To avoid these problems we can use some built-in functions to display a blank page that uses your template and gives you greater control of the page’s content.

First, create a new file in the root directory of your blog.  Name it whatever makes sense to you but make sure to give it the ‘.php’ extension.  Copy the following into the file you have just created:

<?php
define('WP_USE_THEMES', false);
require('wp-blog-header.php');
get_header();
get_sidebar();
?>

<p>Hello!</p>

<?php
get_footer();
?>

You can see an example of this page here – http://joe-riggs.com/blog/blank.php.  You can add any valid html or javascript to the section between the php tags and will be displayed.  If you don’t want to display the header, sidebar or footer you can simply comment out or remove that particular line – ie : delete entire  “get_sidebar();” line to remove the sidebar.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Detect Adblock Users on a Wordpress Blog
  2. Block Spammers by IP address in Wordpress
  3. My Google Page Rank is Increasing!
  4. Blank html template – Transitional dtd
  5. php: Send xml/soap to Secured Server

5 Comments on “Create Blank Page for Wordpress Blog Using Your Theme Template”

  1. 1 Jos said at 9:57 pm on July 21st, 2009:

    Hi Joe,

    Thanks very much for making this clear!
    Just found it on the WP forum.

    Followed all of your steps, did even create the /blank page that’s a good start-off (for later html).

    Then realised, I was lost in first instance (no idea how to attach this page as template).

    Then found this explanation, you might consider to add to above explanation?

    http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    Thanks again.

  2. 2 Laura S. said at 9:42 pm on July 27th, 2009:

    Ok now I’m really confused. I thought the whole point of WP was to enable somebody to easily create pages that are easily editable …?

    I did try to create an easily editable page using “Add Page” but as you said, it included a ton of code from my home page.

    I must be missing something …

  3. 3 Rossie Jordan said at 8:51 am on October 8th, 2009:

    This post is well thought-out and informative.I’m interested,must give a try.

  4. 4 Pascal said at 4:39 am on October 21st, 2009:

    thanks… needed this

  5. 5 Diana said at 7:24 pm on March 15th, 2010:

    I found your post while searching for help in creating a blank page on my blog so that I can easily upload an Amazon aStore. The current settings of my theme prevent the aStore from fully showing up whether I use the inline frame or frameset codes. But unfortunately, I am clueless about even the first step you mention — set up a new file in my blog’s root directory. I have no idea how to do that or even where the root directory is. I’d appreciate your help with this.
    Thanks very much.


Leave a Reply