The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Using "require" function in header.php (6 posts)

  1. WayneSmallman
    Posted 7 years ago #

    Hi guys!

    I've developed a navigation system, which I want to use within WordPress. The system itself is a class file. I'm using the "require" function to pull in the file and instantiating the class, then I'm calling the methods to build the navigation.

    However, I can't find the correct path for my folder "library" which is on the root.

    I've tried everything I know but I can't get at the root from within the "header.php" file.

    Any ideas?

  2. WayneSmallman
    Posted 7 years ago #

    Any takers? I could really do with some help here.

  3. t31os
    Posted 7 years ago #

    More details on the problem would be helpful.

    I assume when you say require, you are referring to...

    require('myfile.php'); etc....

    Could try $_SERVER['DOCUMENT_ROOT'] ...

    Print or Echo out your problem paths, and see what comes up...

  4. Nommo
    Posted 7 years ago #

    From: http://uk3.php.net/function.require

    If you use relativ paths in a php script (file A) that can be required by another php script (file B), be aware that the relativ paths in file A will be relativ to the directory, where file B is stored.
    You can use the following syntax in file A, to be sure that the paths are relativ to the directory of file A:



    if you want to include files with an absolut path reference, you can use:

    require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");

    this way you can organize your files in subdirectories trees.

    Hope that helps?

  5. t31os
    Posted 7 years ago #

    What he said... ;)

  6. WayneSmallman
    Posted 7 years ago #

    @t31os: "I'm using the 'require' function" That's self explanatory. There is only the one such function in PHP, as far as I am aware.

    What I wrote is all of the detail there is to provide.

    I've tried all of the standard global variables and none worked.

    In the end, the only method that would / will work is: require (ABSPATH . '/library/classes/class.page.php');

Topic Closed

This topic has been closed to new replies.

About this Topic