[resolved] include/require a file from another directory (4 posts)

  1. jonathandsimmons
    Posted 4 years ago #

    So I've tried everything I know to include/require a file from another directory within my wordpress install.

    Below is what I've tried can anyone tell me what I'm missing

    Move back through folder to the proper dir:

    setting root path:

    Hardcoding path:

    These are just a few of the many. The folder is two folder back from my theme folder. Coming the other way its 1 folder deep past root.

    each time I get the error below:
    Warning: include(/home/mylogin/public_html/myfolder/myfile.php) [function.include]: failed to open stream: No such file or directory in /home/example/public_html/wp-content/themes/my_theme/home.php on line 13

    Its trying to add on the path to the end of home.php which of course won't work it doesn't exist. I'm aware normally you would ../../ however many directories you need to go back but that just isn't working.

    What am I missing?

  2. tugbucket
    Posted 4 years ago #

    try something like:

    <?php include(home_url().'/path/to/your/file.txt'); ?>

  3. rjanson
    Posted 4 years ago #

    Is the file completely outside of your wordpress installation directory? If so, it might work better for you to create a symlink to it within the wordpress directory and include/require that.

    ln -s /path/to/file/myfile.php /word/press/location/plugins/myfile/myfile.php

  4. jonathandsimmons
    Posted 4 years ago #

    I fixed it. I should know by now not to code past midnight.

    To be honest it must have just been a type somewhere because this morning I opened the file and typed the following and it worked fine.


Topic Closed

This topic has been closed to new replies.

About this Topic