I’m working with an existing PHP web application. It’s site structure is similar to:
- public_html
- include
- header.php
- style.css
- footer.php
- blog
- include
I’ve installed WordPress in /blog. I am trying to create a WordPress theme using the dynamic elements of the external PHP app.
Here is an example of /blog/wp-content/themes/custom-theme/index.php:
<?php
include_once("../../../../include/header.php");
?>
The theme is not reproducing the header code. I’ve tried variations of the relative path, just in case, with no success. Are there other considerations I haven’t taken into account?
If WordPress is in /blog, there’s a convenient constant called
ABSPATH
that holds the path to that folder. So:Or directly:
Seeing that you’re already using the correct relative path, though, be sure to include that file where relevant. If you’re including it in an html comment or something like that, you’ll get unexpected results.
I believe the “file_get_contents” could work in this scenario too.
It could also be handy if the external php file is part of a different program.
“file_get_contents” is a php method which loads entire files into a string.
See us3.php.net/file_get_contents
A handy call in various situations.
I used this to embed an ASP menu inside WordPress. See stackoverflow thread with an example here:
How to Include an .asp menu file inside a php file? (WordPress Blog folder within ASP Site)