Learning Is Fun

Talks on Web Technology and Better Product Development

WordPress: How to add and link static or custom pages

November2

When I was new to wordpress theme development, I faced a common problem that many others might have faced. That is adding or linking or integrating a static or custom page in your wordpress site. It is very possible that you may prefer to keep one of your page or file linked as the following:

http://www.yoursitename.com/products.php

Sometimes this kind of requirement arrive that you have no other option but to do it.

But you know this kind of link will not directly appear in your wordpress blog or site because of the unique linking structure of wordpress. Most probably you will get a 404 error i.e. file not found error. So, if you want to link directly, you need to follow a simple trick. This trick is simple, small and intereting.

If you want to add and link your custom or static pages, follow these steps and you will get smooth result:

Step One: Changing the header of the php file

In this article, we will add a php file products.php in our wordpress blog. So, please create your products.php file.  Now open you products.php file and add the following two lines at the top of the file and save your file.

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

Remember, these lines will be the topmost lines in your products.php file. OK? See below how I added.

<?php
	define('WP_USE_THEMES', false);
	require('./wp-blog-header.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Our Products</title>
</head>
<!-- Other lines of coding -->

Why are we adding these two lines? Because we are telling wordpress that this file will not use wordpress themes and we are going to link it in a different way. So, wordpress do not force to link in its usual way.

Step Two: Saving in the public_html or root folder

Now upload it in the wordpress installation directory so that it looks like:

http://www.yoursitename.com/products.php

Done? Great!

Step Three: Linking the products.php file in a usual way

Now in the code of any wordpress file where you want to link your products.php file, keep the html linking as usual or what we say relative linking. For example, in the contact us page, I am creating such a link in the body section:

<a href="http://www.tanzilo.com/wp-admin/products.php">Our Products</a>

And yes! We are done!
Test now if it works for you.

Thus, you can add any number of pages in your wordperss site. I do not know exactly when you may need to link this way. I had to do it time to time depending on the client’s project requirement.

Thus, you can also protect your pages from permalink (dot)htaccess in wordpress.

Thanks for reading.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
posted under Blog, PHP, Wordpress
3 Comments to

“WordPress: How to add and link static or custom pages”

  1. On December 5th, 2008 at 10:33 am Simplistic Thoughts Says:

    Does this also work for inserting html pages. I have an html page that I would like to add as a wordpress page. I have created a folder, inserted the html page (tried as both index.html and index.php) and various files) when I go to that location, nothing shows up. I just get the normal theme. I tired adding you code as well, but that also didn’t work. Any suggestions?

  2. On December 5th, 2008 at 10:42 am admin Says:

    I think you have a linking problem.

    Create a file test.php according to the above way
    Upload it in your root folder may be in public_html
    Uhen check it.

    And also please follow all the steps.

  3. On February 12th, 2009 at 11:06 pm Sneha Gupta Says:

    Hello,
    I am very glad to u because this blog is very good.

Email will not be published

Website example

Your Comment: