Solved

include file not working

Posted on 2011-09-05
10
429 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:petewinter
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36484168
Can you post the error?
0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36484187
Try using the full pathname and see if that fixes the problem:
 
<?php include("http://mysite.com/templates/header2.tpl"); ?>

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

Author Comment

by:petewinter
ID: 36484241
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?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
ID: 36484320
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 http://php.net/manual/en/function.include.php 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.

<?php
$now_at_dir = getcwd();
chdir(realpath(dirname(__FILE__).'/../../../somewhere/'));

# Out of the general area
require_once('a_differnet_path/browse_wine.php');

chdir($now_at_dir);
?>

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.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36484329
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"); ?>

to

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

Note the extra 'dot'

0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36484332
Typo alert

file system file   = file system LEVEL

Sorry.

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36484532
Try
<?php
   $path = bloginfo("template_url")."/header2.tpl";
   include($path);
?>
0
 

Author Closing Comment

by:petewinter
ID: 36484630
Many thanks
0
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 36484637
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

0
 
LVL 17

Expert Comment

by:OmniUnlimited
ID: 36484652
No problem.  Best of luck to you!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question