1

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

9
  • 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
    Commented 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. Commented Oct 6, 2015 at 16:06
  • Gotcha. Your original post specifies with the scheme, which is what confused me.
    – Chris Cox
    Commented Oct 6, 2015 at 16:08
  • Sorry, mah bad. Commented Oct 6, 2015 at 16:11
  • get_stylesheet_directory()? Commented Oct 6, 2015 at 16:12

2 Answers 2

5

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.

2

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
  • 2
    The easiest way to do this would be to regex it. Famous last words. Commented Oct 6, 2015 at 16:13
  • There you go, should be slightly faster without the regex.
    – Chris Cox
    Commented Oct 6, 2015 at 16:21

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.