I have created a custom file that both the header and the footer needs to render certain content.
If I only do include($_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/myTheme/myCustomFile.php');
in the header.php
file it works as expected BUT only in the header.
Likewise with the footer, If I only do include($_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/myTheme/myCustomFile.php');
in the footer.php
file it works as expected BUT only in the footer.
The moment I have the include on both files, the page renders up until the footer starts and then stops rendering.
How can I include this file so it can be accessed from anywhere in the theme?
I also tried the other import methods in PHP - require, require_once, and include_once – same deal.
Thank you in advance.
myCustomFile.php
is in theme directory, so just addinclude 'myCustomFile.php';
in both files (footer and header). Do you have function or class definitions in included file?myCustomFile.php
fine. I do have functions in the custom file, but I don't think they are interfering because then it would not render on the header.