I'm trying to include a PHP file which is in the root of my Wordpress theme file.
E.g localhost/mywordpresssite/wp-content/themes/mytheme/myfile.php
I'm trying to call it from a file footer.php which is located in parts > shared
E.g localhost/mywordpresssite/wp-content/themes/mytheme/parts/shared/footer.php
I can confirm that when visiting the full URL in the browser, the file does show, so it's definitely the right path.
I have been unable to include this file in a number of different ways:
1) Preferred way - using the stylesheet directory URI
<?php
$stylesheet_root = get_stylesheet_directory_uri();
include $stylesheet_root.'/myfile.php';
?>
This should find the stylesheet URI and then find the file, but I get this error:
no suitable wrapper could be found
I understand the reason this happens is that it is not secure and that allow_url_include is turned off by default, so what's the best way?
2) Coding in the URL to climb up two directories
This seems like a fairly sensible way because the files will always be relative two directories apart from each other. But this seems to do nothing. It's still looking for the file within the same directory:
<?php include '../../myfile.php'; ?>
3) Just hardcode the stupid thing in.
Yet this STILL doesn't work, even though the URL placed here is tested in the browser and does successfully load the right file. It won't load it into the file where the include is though...
<?php include 'localhost/mywordpresssite/wp-content/themes/mytheme/twitter-feed.php'; ?>
Gives the error:
Warning: include(localhost/mywordpresssite/wp-content/themes/mytheme/twitter-feed.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/mywordpresssite/wp-content/themes/mytheme/parts/shared/footer.php on line 3
What else can I do?
include( 'twitter-feed.php' )? What does that produce?include '/var/www/mywordpresssite...get_stylesheet_directory_uriwill get you an URI, but you want a local file system path. And there’s a function for that as well –get_stylesheet_directory