Nov 2, 2008 - PHP, Wordpress    14 Comments

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:

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.

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

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:

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:

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.


  • 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?

  • 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.

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

  • @ Manish

    better you put the page in the same directory where you installed wordpress.

  • It really works and solved my problem for the same. Thanks much

  • Thank you for sharing this! This solved my problem but I also noticed that wordpress consider your “products.php” as a “home” page of template. So, the following code is not printed on it: I’m not a home template. Do you have any idea about how print “I’m not a home template” like this condition in “products.php”? Thank you again!

  • @ Luisa Ambros

    you question is not clear. i think you may have missed some points.

  • Ok! Following your steps, everything worked fine. In “products.php” I used the wordpress code: get_header(); .

    The header.php have this:
    if (!is_home()) { echo ‘I am not home.php’; } else { echo ‘I am the home.php’; }

    is_home() is a wordpress conditional tag that checks if the main page is being displayed (most of times “home.php”).

    When I access “products.php” it shows “I am the home.php”, what means that wordpress is understanding “products.php” as the main page.

    Do you know how to make wordpress recognize “products.php” as NOT the main page so it can print “I am not home.php”?

    Thank you!

  • @ Luisa Ambros

    you can try “Template Name” feature from:

    Basically two steps:
    1. Turn your file as template.
    2. When you create a page, set the “Template” value from “Page Attributes” section.

    Also try to double check by using is_home() and is_front_page()

  • Fantastic! This post saved me days of frustration, and it is helping people like me YEARS after you initially wrote it!

    You may want to add how to include and link to the CSS files and images for the new web page. I linked to my new pages’s CSS files by following the same procedure as uploading the new PHP page and linked accordingly. As for the images, I just uploaded to the usual WP media file, then copied the image’s URL and added that to my <img src="etc. . ." in my HTML file.

    Thanks again!

  • i have a client that he wants me to use wordpress, im really frustrated with this problem. its seems it doesnt work for me. i tried and followed all instructions.

  • Thanks for the helpful info above. My question is just the reverse. I have a static html page that won’t link to the WordPress pages. What is the correct link stucture? In other words a vistor is looking at my html page and I have a llink in the static menu called Blog. My actual blog is sitting on a page in WordPress called Blog. So can you tell me exactly how that link looks, because the page_id=4 stuff is not working.


  • This article was a great help in that I can now link static pages with some of this code.

    However, I wanted to call some parts of my static page as PHP includes from my template folder.

    Your information makes it possible to successfully name and link PHP pages to WordPress any way that one wants. But when I try to swap out my HTML for PHP includes, pages don’t link.

    How does one do this and get it to work?

  • Thanx, it was really helpful and solved my problem. I am really grateful …..

Got anything to say? Go ahead and leave a comment!