Solved

include file not working

Posted on 2011-09-05
10
437 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 look for a specific file type in a local or remote server directory using PHP.

751 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