WordPress: How to add and link static or custom pages
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.