include - How do IIs it possible to execute an external PHP filefunction inside Wordpress?

On my set-up, there is the regular website which consists of a header and content (both printed from separate PHP files

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
  • Hi J. Watkins, could you provide more details on what you've tried already (and why it didn't work)? – kraftner 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 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. – J. Watkins Commented Jun 11, 2014 at 12:55
  • What paths have you tried for include? – kraftner Commented Jun 11, 2014 at 12:58
  • I've tried using both absolute and relative paths as well as just specifying the containing folder. – J. Watkins Commented Jun 11, 2014 at 12:59
Add a comment  | 

2 Answers 2

Reset to default 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.

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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信