Blog
Get Your WordPress Multisite Blog Slug
- September 23rd, 2010
- WordPress
- 0 Comments
I chose this subject to write about for two reasons. One: I’m sure there are folks out there who will find this useful. And Two: I can never remember it myself so by writing about it here, I won’t have to remember, I can just refer back to my own blog!
Often, when using WordPress multisite as a content management system rather than a blog network, I have the need to use a blog slug in image paths, or when doing DB queries or whatever. There are lots of reasons, but here’s how you get it >
// This is one way $blog_details = get_blog_details($GLOBALS['blog_id']); $slug = str_replace('/','',$blog_details->path); echo $slug; // This way makes more sense to me since there's already a global $var for the path $slug = str_replace('/','',$GLOBALS['path']); echo $slug;
I find the $GLOBALS variable to be really useful. If you’d like to see all the stuff you can get out of there, just drop this line in your theme somewhere (it’s quite long, so best not to do it on a production site)-
print_r($GLOBALS);
Enjoy!
Leave a Comment