0

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.com/includes/) and a Wordpress blog based in a subdirectory (domain.com/blog/).

I want to include domain.com/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.com/includes/header.php.

Thanks in advance.

4
  • Hi J. Watkins, could you provide more details on what you've tried already (and why it didn't work)? Commented Jun 11, 2014 at 12:48
  • Hi @kraftner. Thanks for the response. I've tried adding the include through <?php include('/includes/header.php'); ?> as well as explicitly stating the full path with domain.com 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 the ABSPATH. <?php include('/includes/header.php'); ?> works fine on the main site and prints the contained HTML without error. Commented Jun 11, 2014 at 12:55
  • What paths have you tried for include? Commented Jun 11, 2014 at 12:58
  • I've tried using both absolute and relative paths as well as just specifying the containing folder. Commented Jun 11, 2014 at 12:59

2 Answers 2

0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.