Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

include file not working

Posted on 2011-09-05
10
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

671 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