Hi Everyone I am having a relative path issue with linking a css file using a absolute path.

Basically I am having the exact same problem as the person here however I do not want to use the URL of the site to link the css file.

Anything I do, word press tries to put its own file path in front of it.

so if i have done this:

wp_enqueue_style('media', $_SERVER["DOCUMENT_ROOT"] . '/assets/css/media.css');

word press will give me this :

<link rel="stylesheet" id="media_style-css" href="" type="text/css" media="all">

and funny enough if I do this:

wp_enqueue_style('main_style', $_SERVER["HTTP_HOST"] . '/assets/css/style.less');

Wordpress decides to give me this....

<link rel="stylesheet" id="main_style-css" href="" type="text/css" media="all">

Is there any way to actually get to the root of my site via function.php or does wordpress just not let you via absolute path?

  • 1
    What if you just do wp_enqueue_style('main_style', '/assets/css/style.less'); ? Commented Jun 27, 2015 at 0:17
  • href = url only you cannot link files using the path, only the url, when you hear of relative paths being used, they actually mean relative to the url unless used within php, if you want to load files using the path use include / require but you are missing a opportunity to cache the files. Is there any reason you are looking to use a path ? Btw $_SERVER['host'] is client side
    – David
    Commented Jun 27, 2015 at 1:41
  • @czerspalace that takes me to the root of the blog because wp puts its root in front. would end up blog/assets/css/...
    – Flo
    Commented Jun 27, 2015 at 22:35
  • is Wordpress hosted in a subdirectory of your main site? What I mean is do you have a site at / and WordPress is installed at /blog/ ? Commented Jun 28, 2015 at 10:58
  • @czerspalace yes the root is outside the wordpress directory.
    – Flo
    Commented Jun 30, 2015 at 23:41

1 Answer 1


If you want the absolute path to your theme's stylesheet directory you could use get_stylesheet_directory(). If you want the URI of your theme's stylesheet directory you could use get_stylesheet_directory_uri().

get_theme_root() will return the absolute path to the themes directory.

get_home_path() will return the absolute filesystem path to the root of the WordPress installation.

Once you've got your absolute path with one of these methods you can then do what you need to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.