On my set-up, there is the regular website which consists of a header and content (both printed from separate PHP files located in domain/includes/
) and a Wordpress blog based in a subdirectory (domain/blog/
).
I want to include domain/includes/header.php on the main Wordpress skin. I have tried require_once
, include
, specifying the ABSPATH
in the wp-config
, and various other techniques but none of them have worked for me.
Printing the header.php contents to Wordpress skin is vital and there is no compromise for it in my workflow.
I would greatly appreciate any advice as to how I can get this script working, whether it be through a plugin or some edit to the core files, without having to change the location of domain/includes/header.php
.
Thanks in advance.
On my set-up, there is the regular website which consists of a header and content (both printed from separate PHP files located in domain/includes/
) and a Wordpress blog based in a subdirectory (domain/blog/
).
I want to include domain/includes/header.php on the main Wordpress skin. I have tried require_once
, include
, specifying the ABSPATH
in the wp-config
, and various other techniques but none of them have worked for me.
Printing the header.php contents to Wordpress skin is vital and there is no compromise for it in my workflow.
I would greatly appreciate any advice as to how I can get this script working, whether it be through a plugin or some edit to the core files, without having to change the location of domain/includes/header.php
.
Thanks in advance.
Share Improve this question asked Jun 11, 2014 at 12:21 J. WatkinsJ. Watkins 32 bronze badges 4 |2 Answers
Reset to default 0Using the domain name in the path won't work; you're not trying to specify a URL, but a path to a file, be it relative or not. Using
include(ABSPATH . '../includes/header.php' )
should work.
/includes/header.php
doesn't work because the location of the blog
folder doesn't is not the root folder (/
), but most likely a few levels down.
You can execute by providing the exact path to your file starting from server root.Add the following code to your theme's functions.php file.
function hook_addl_header_elements() {
require_once('/home/hosting-username/public_html/my-domain-folder-com/wordpress-dir/wp-content/custom-php/user.php');
?>
<!-- html scripts to add in header can come here -->
<?php
}
add_action('wp_head', 'hook_addl_header_elements');
This will execute the php file user.php whenever the site is loaded.This is suitable when you want the php file to do other things like capturing $_SERVER variables etc.
This file can execute word press loop WP_query as well.
However that is not recommended as a output in header will not be desired.
However it will do the job of running the php file perfectly.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742286054a4415340.html
<?php include('/includes/header.php'); ?>
as well as explicitly stating the full path with domain at the beginning. I've tried a few different functions:include
,require_once
as I saw somebody suggest on a similar question, as well as including theABSPATH
.<?php include('/includes/header.php'); ?>
works fine on the main site and prints the contained HTML without error. – J. Watkins Commented Jun 11, 2014 at 12:55include
? – kraftner Commented Jun 11, 2014 at 12:58