Reputation: 123
Wordpress is installed in a directory called 'blog' on my website and it uses a custom theme:
mysite.com/blog/wp-content/themes/mytheme/
I would like to alter the theme so that it calls the same header and footer as the rest of my site, which are in a folder off the root directory of my site called 'include':
mysite.com/include/header.php
Is this possible?
At the moment, my custom theme has a complete copy of the header and footer saved in it's local directory (along with the relevant CSS, JS etc.) but it is becoming a real pain having to maintain two identical copies.
These copies are referenced in the theme using ABSPATH, but this seems to have limited scope as the furthest back I have been able to get is to the /blog/ directory. If I replace ABSPATH with an absolute URL, I get an error about security.
Any help or advice would be greatly appreciated.
Upvotes: 3
Views: 2192
Reputation: 123
As per Thomas's suggestion, this worked perfectly (source: https://css-tricks.com/php-include-from-root/)
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/include/header.php";
include_once($path);
Upvotes: 2
Reputation: 995
In the theme's default header.php file, call include('/path/to/your/include/header.php');
. This will include your header.php file and use it instead.
Upvotes: 0