• my first post. πŸ™‚

    I am wondering how to determine the relative path from a page I’ve created via WordPress interface to somewhere else in my site structure. That is, where is that page in my site’s directory tree? So I can create relative path from that page to content that is not in the WP database. Specific example follows…

    I know there are some reasons not to use relative URLs, but in this case I have.

    I have a page with some custom content. The assets are in a directory called “my-assets”, which is in the site’s html directory. For example:

    mysite.com
    __ / html
    _____ / wp-content
    _____ … other files and folders …
    _____ / my-assets
    _______ / clients-assets
    __________ / css
    __________ / images
    __________ / etc
    _______ / other-assets

    I was uncertain how to path to the content from the page – page is a normal WP page, created from the Pages interface. I took a guess that pages reside at same level as index.php, inside /wp-content, so set a path relative to that location. It worked.

    For example,

    <img class="third" src="../my-assets/clients-assets/images/photos/sanfrancisco/209x171/209by171-1.png">
    places an image, and

    <link rel="stylesheet" href="../my-assets/clients-assets/css/clients.css">
    loads the required stylesheet.

    Great, it seemed I know where my path originates, so can link to any file from the page.
    However I tried connecting to same content as if my page were at the root level of the html directory (not in wp-content). Like so…

    <img class="first" src="/my-assets/clients-assets/images/photos/sanfrancisco/249x150/249by150-3.png">

    <link rel="stylesheet" href="/my-assets/clients-assets/css/clients.css">

    No “..” before “/my-assets/” and it still worked. Image loaded, stylesheet loaded.

    Both can’t be right, can they? Is WP correcting the path that’s in error?
    So what is the proper relative url from a WP-generated page? From the page to the site root for example. That is, where does the page reside? Do I set that somewhere or is it a constant?

    Much thanks for any help with this question.

  • The topic ‘Where does page live in site structure? and relative paths from that page’ is closed to new replies.