include file not working

petewinter used Ask the Experts™
I want to add an include file to my wordpress header, but it's not showing.

Code below:

<?php include("/templates/header2.tpl"); ?>

The path is correct. Any idea's why it is not showing?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Can you post the error?
Try using the full pathname and see if that fixes the problem:
<?php include(""); ?>

Open in new window

If it still is not showing up, I would ensure that you are updating the proper header.php file in the proper theme.


PragmatiCoder - No error. Just not displaying

OmniUnlimited - Tried the pathname and it did not fix the problem.

I can get around the issue including in the same folder or updating the header.php file, but wanted to work out why it didn't work?
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

If you are absolutely sure that you are updating the correct header.php file in the correct theme (ie you can make other changes to the file and they show up) then you have to have a problem with the path.

There is some handy code listed on by bimal at sanjaal dot com that says the following:

When two different files located in separate directories try to INCLUDE/REQUIRE the relative file names, this may help you correctly FIND the included files.

The code is a snapshot only. Your environment might change.

$now_at_dir = getcwd();

# Out of the general area


The basic trick is in saving the current directory, changing to the required directory, including the file, and then return back to the original directory.
DId you check permissions on the header2.tpl file?

Also, include works at the file system file, not the web server level so /templates would be a top level folder in the file system. Maybe you should try making the path relative to the current folder by changing it from

<?php include("/templates/header2.tpl"); ?>


<?php include("./templates/header2.tpl"); ?>

Note the extra 'dot'

Typo alert

file system file   = file system LEVEL


   $path = bloginfo("template_url")."/header2.tpl";


Many thanks
Try using this to include it:

Rename your file to header2.php

Then to include it in your template you would use:
<?php get_template_part('/top/header2'); ?>

Open in new window

No problem.  Best of luck to you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial