0

Is there a way to get a path to the themes directory without the current theme in the path?

ie, in a standard WP install, I would want a reference to:

C:\xampplite\htdocs\sitename/wp-content/themes/

But the TEMPLATEPATH constant returns...

C:\xampplite\htdocs\sitename/wp-content/themes/currentActiveTheme

4 Answers 4

5
dirname( STYLESHEETPATH );

That will return the theme directory.

Never assume /wp-content/ below ABSPATH. I’m using often a different directory and domain for wp-content to enable cookieless requests to theme files. Bad plugins and themes break terribly in such cases.

Addendum

Or use get_theme_root() for the file path and get_theme_root_uri() for the URI. Both are defined in wp-includes/theme.php.

4
  • + 1 Thanks. This works too. Would there be any benefit to using this vs imHavoc's answer?
    – Scott B
    Mar 24, 2011 at 13:09
  • @Scott B There should be no difference. STYLESHEETPATH is defined in wp-includes/default-constants.php calling get_stylesheet_directory() which is asking get_theme_root().
    – fuxia
    Mar 24, 2011 at 13:46
  • actually, after further review, yours is the more appropriate answer for my question. it returns a file path, not a URL path as get_theme_root_uri() does (c:\ as opposed to http://) and since I'm moving files, that's what I needed in this case.
    – Scott B
    Mar 24, 2011 at 17:37
  • @Scott B I added the two functions for for the path and the URI to complete the answer.
    – fuxia
    Mar 25, 2011 at 0:22
2

There is no THEMEPATH constant, but you can use the get_theme_root_uri() function to retrieve the path to the themes folder.

2
  • This looks like the best option. Testing it now.
    – Scott B
    Mar 24, 2011 at 12:42
  • This works perfectly, however, in this case, I'm looking for a file path, not a URL path. I'm moving files on the server from a plugin folder to the themes folder. Your answer works fine though, depending on the context of the question.
    – Scott B
    Mar 24, 2011 at 17:40
2

WP_CONTENT_DIR and WP_CONTENT_URL as well as content_url() get you most of the way there.

0

You can use the constant ABSPATH and just append to it wp-content/themes/ so:

ABSPATH . "wp-content/themes/" 
4
  • Can the user specify any directory other than wp-content/themes to store their themes?
    – Scott B
    Mar 23, 2011 at 22:43
  • @Scott: It is possible but very hard to acomplish and not very likly that anyone has.
    – Bainternet
    Mar 23, 2011 at 22:51
  • 4
    Two lines in wp-config.php aren’t that hard. ;) Just define WP_CONTENT_DIR and WP_CONTENT_URL.
    – fuxia
    Mar 23, 2011 at 23:13
  • @toscho: thanks, you learn new stuff every day, i was just reading about it at codex.wordpress.org/Determining_Plugin_and_Content_Directories
    – Bainternet
    Mar 23, 2011 at 23:41

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.