Getting out side of wp root folder from function.php using absolute path

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="http://192.168.1.111/blog/var/www/html/assets/css/media.css?ver=4.0.5" 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="http://192.168.1.111/blog192.168.1.111/assets/css/style.less?ver=4.0.5" 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?

Topic functions linking css Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.