I basically want the output of get_stylesheet_directory_uri(), but without http(s) and the domain.

  • Sorry, I don't quite understand what you're looking for. You want to return two strings, one of which is "http://" or "https://" and the other is "/wp-content/themes/my-theme"?
    – Chris Cox
    Oct 6, 2015 at 16:04
  • Not quite. I want to get exactly what the get_stylesheet_directory_uri() function returns, just without "http(s)//:mydomain.com" and ONLY get, for example: /wp-content/themes/my-theme. Oct 6, 2015 at 16:06
  • Gotcha. Your original post specifies with the scheme, which is what confused me.
    – Chris Cox
    Oct 6, 2015 at 16:08
  • Sorry, mah bad. Oct 6, 2015 at 16:11
  • get_stylesheet_directory()? Oct 6, 2015 at 16:12

2 Answers 2


Use parse_url(), because it exists exactly for that reason:

$path = parse_url( get_stylesheet_directory_uri(), PHP_URL_PATH );

Chris Cox’ solution will fail when the wp-content directory runs under a different domain than the rest of the site.


The easiest way to do this would be to regex it. Use preg_replace() or similar to trim the output of get_site_url() from the output of get_stylesheet_directory_uri().

Edit: actually, str_replace would do the job without resorting to regex.

str_replace(get_site_url(), '', get_stylesheet_directory_uri());
  • 2
    The easiest way to do this would be to regex it. Famous last words. Oct 6, 2015 at 16:13
  • There you go, should be slightly faster without the regex.
    – Chris Cox
    Oct 6, 2015 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.