How can I get the root directory of my site? I want to use it as the src
for <img>
.
For example If I install the wordpress on www.mysite.com/blog/
, the root is /blog
.
But If I install it to www.mysite.com/test/blog
, the root is /test/blog
.
I tried to use the snippet from this question, but it returns the whole path as seen in FTP. So instead of returning just /blog
, it returns /home/public_html/blog
which won’t work if used as src
in image tag.
Any solution? Thanks.
You may use
site_url()
(eventually withecho
) to get absolute path with server name and directory. Also, have a look at wordpress documentation about similar functions & what they provide.You may have better luck over at the WordPress Stack Exchange site 🙂
And this suggestion to use
ABSPATH
didn’t help on that thread? https://stackoverflow.com/a/2356467/413254site_url() return the path with http, in some cases, it is not allowed if the server turns off url inclusion. You can use the function below to get the root path of wordpress installation folder: