Include file from higher level

I created a custom page template where I want to present some data specific for that page.

The file is placed in

wp-content/themes/themename/page-templates

In that file I want to include another php file from the parent directory. That file is placed in:

wp-content/themes/themename

So in the file i write:

<?php include('../Sorting.php');?>

But I receive an error saying the file doesn’t exists.

Warning: include(../Sorting.php) [function.include]: failed to open stream: No such file or directory

I’m not that much into wordpress so I theorized that it was something to do with the include function but it works fine if I put the files in the same folder though.

1 Answer
1

You need to use get_template_directory(), this function will return local server path of you template and then you can use that path to access required file.

So in your case it would be something like below:

include get_template_directory() . "/Sorting.php";

PS: Mind the spelling of your file.

Leave a Comment