We have a web application that we run inside of WordPress in order take advantage of WordPress’s authentication. To make this work, we created a template type for our application that simply includes our application’s start page.
While a little bit of hack, this works great, except for once aspect – all the relative URLs now use the WordPress’s page as its base, instead of the actual path to the resource. For example, if my application’s page is at http://mysite.com/myapp
, a relative link to a stylesheet would result in http://mysite.com/myapp/css/stylesheet.css
, as expected.
Unfortunately, this is not the actual location of the stylesheet. The actual location of the stylesheet is something like this: http://mysite.com/directory1/directory2/directory3/css/stylesheet.css
.
How should I go about linking to this resource in my web application if the base URL won’t accurately reflect the location of the resource?
Note: I am not able to use absolute links as we develop locally, which obviously does not have the same directory structure as the WordPress site.
../directory1/directory2/directory3/css/stylesheet.css
should get you there if I am reading your description accurately.However, I would be very cautious using relative links in WordPress. They do not always work the way you’d expect because a lot of ‘directories’ don’t actually exist. They are fabricated by WordPress and
mod_rewrite
. The two conspire to lie about filesystem structure. For example, there is nohttp://blog.com/category/cat-a
. A relative link on that page would be broken.You are better off using
bloginfo
orsite_url
and constructing absolute URLs.site_url
would the function to prefer.