I basically want the output of get_stylesheet_directory_uri()
, but without http(s) and the domain.
2 Answers
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());
-
2The 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. Commented Oct 6, 2015 at 16:21
get_stylesheet_directory()
?