0

Possible Duplicate:
Wordpress root directory

I need to write a file in the root directory on a wordpress installation. This need to be in the same place as the wp-config.php file.

But i need a way to call the root url.

Is there a wp_root_dir() like function

Community
  • 1
  • 1
David Allen
  • 1,123
  • 2
  • 10
  • 24

2 Answers2

0

Do you want root url or root dir?

Given that you're putting this file into the root of your wordpress I assume its not a plugin or something like that.

Here is how to get the root url

<?php echo get_bloginfo('url'); ?>

Otherwise if you want the path (to include() for instance) its perfectly reasonable to just do:

../../../file-in-root.php -> as many ../s as you need to go back directories

I do this all the time. If you think your directory structure may change a lot, you can just put the whole path to the file e.g.

/home/w/o/wordpress/web/public_html/file-in-root.php

If you're creating a plugin and you don't know the path to the file then obviously it would be different, but there are wordpress functions for that. However as you're using root I guess this is just for your own server/website configuration and this will be fine.

Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
0

If you mean on the client side (http://www.myreallyawesomewebsitethatuseseordpress.com/blog/wordpress/), you can use get_bloginfo('url'). This will return the url which wordpress is installed.

If you mean on the server side, you can use the ABSPATH variable.

Usage:

Client side:

<?php
    echo "You are using this site. Wordpress is on" . get_bloginfo('url');
?>

Server side:

<?php
    echo "On the server, Wordpress is installed on" . ABSPATH;
?>
Anish Gupta
  • 2,218
  • 2
  • 23
  • 37