Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - Get root directory?

Tags:

wordpress

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.

like image 224
hrsetyono Avatar asked May 28 '13 03:05

hrsetyono


People also ask

How do I find the root directory in WordPress?

To find your WordPress root directory from your cPanel dashboard, first, log in to your cPanel and then find the 'File Manager' as shown below. From here, you will be able to access all the files which have been installed or used on your website inside the 'public_html' folder.

How do I find the root directory path?

In order to get the root directory path, you can use _DIR_ or dirname(). echo dirname(__FILE__); Both the above syntaxes will return the same result.

What is the root of the domain WordPress?

The domain root folder is typically called html, www, or public_html on most web hosts. Some WordPress installs are pretty gnarly with folders inside of folders inside of folders, and finding the folder that the host considers to be the primary domain root folder can take some digging.


1 Answers

You may use site_url() (eventually with echo) to get absolute path with server name and directory. Also, have a look at wordpress documentation about similar functions & what they provide.

like image 146
mrówa Avatar answered Oct 08 '22 03:10

mrówa