I want to get just the subdirectory name from the network site, and I've gone through the codex and cannot find a function that already does this.
I have come up with a few options to get to the point I need, but I wanted to know if there was either:
- a function I havent seen yet
- which of these options works the best and efficiently
$url = get_bloginfo( 'url' ); // output http://example.com/site1 $str = preg_replace( '#^https?://#', '', $url ); // output example.com/site1 $dom = parse_url( $url ); $dom = str_replace( 'www.', '', $dom['host'] ); // output example.com $out = str_replace( $dom . '/', '', $str ); // just the subdirectory
$url = get_blog_details()->path; // output /site1/ $dom = str_replace( '/', '', $url ); // output site1
Obviously option 2 is less lines, but I'm not sure if it is the most efficient or cleanest.