I have a theme which - I was quite proud of myself! - I designed to be installed in wp sites where wp is on root level.

Then half my users installed the theme on a mysite.com*/wordpress/* !

...and it no work...

So some path conversion are in order. I created a number of constants so I didn't always have to rewrite paths. Example:

//http constants
$symbiostock_template_directory = get_bloginfo('template_directory');

define('symbiostock_CLASSDIR', $symbiostock_template_directory . '/inc/classes' );

...and more constants like this for various paths

//filepath constants 
$symbiostock_theme_root = get_theme_root() . '/symbiostock';
define('symbiostock_STOCKDIR', $_SERVER['DOCUMENT_ROOT'] . '/symbiostock_rf/' );

...and more constants like this for various paths

define('symbiostock_STOCKDIR', $_SERVER['DOCUMENT_ROOT'] . '/symbiostock_rf/' );

These should work, right?

Is there a nice universal way to get wordpress operating from any level? A "best practice" tutorial out tehre?

1 Answer 1


The WordPress directory path is available in the constant ABSPATH. Be aware this is not related to the wp-content directory. The constant WP_CONTENT_DIR could be set to exactly the same value. Or another directory on the same level where WP_CONTENT_URL is another domain name.

There doesn't even have to be a wp-content equivalent: themes, plugins, languages and so on might be spread over different directories.

Do not rely on default paths.

define('symbiostock_STOCKDIR', $_SERVER['DOCUMENT_ROOT'] . '/symbiostock_rf/' );

This will break in many setups. Use get_template_directory_uri() instead, and let WordPress figure out where that is.

Another word on constants: avoid them. There might be collisions with other people’s code. They are slow. Use a helper function to load classes instead, and solve all path problem in that function’s body, not in the global namespace.

  • A BIG thank you on that. Shows also I have a few things to learn :D. Bookmarked! Even the thing on constants...I thought it was a great way to make life easy and consistent! Didn't know there was a price :D. Mar 27, 2013 at 9:57

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.