WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/get id from blogname

Contents

Description

Given a blog's (subdomain or directory) name, retrieve it's id.

Usage

<?php get_id_from_blogname$slug ?>

Parameters

$slug
(string) (required) The blog's slug
Default: None

Return Values

(integer) 
The blog id
(NULL) 
If there isn't a blog with the provided slug

Examples

Getting the the id of a blog by name ($slug)

$slug = 'first-site';
$id = get_id_from_blogname($slug);


Switching blogs based on the blogs name ($slug)

$slug = 'another-site';
$id = get_id_from_blogname($slug);
switch_to_blog($id);

// do great things

restore_current_blog();

Notes

Change Log

Since: 3.0.0

Source File

get_id_from_blogname() is located in wp-includes/ms-blogs.php

Related

 

See also index of Function Reference and index of Template Tags.