This is a solution written basing on Tom J Nowell‘s idea and answer to this question. It prints out list of all sites in WordPress Multisite installation (alphabetically sorted) as simple line (separated with pipe —
Single site or single theme approach
To get this solution running, you need to edit
shortcodes.php file from your currently selected theme. To do this, you need to:
Themes > Editorsection from left sidebar,
- select theme from
Select theme to editlist and click
shortcodes.phpfile in the right sidebar,
- in code editor, near the end of this file (before first occurrence of
add_shortcodecall) add code given below,
- save changes by clicking
In multi-site installation
Themes > Editor section is available only in network administration panel (i.e. My Sites > Network Admin > Themes in top menu). I don’t know, where to find corresponding section in single-site WordPress installation.
It may happen, that your particular theme does not contain
shortcodes.php file. In this case or in any other case, when you can’t access
shortcodes.php file in themes editor (or themes editor itself) the only option, you’re left with, is to:
- access your WordPress installation via FTP,
- navigate to themes folder and your theme subfolder,
shortcodes.phpfile from remote FTP server to your local computer (or create it locally, if it does not exist),
- add following code to the end of your locally stored file,
shortcodes.phpfile and upload it back to your FTP server, overwriting existing one.
Code to be added to
$result = ”;
$sites = array();
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE spam = ‘0’ AND deleted = ‘0’ and archived = ‘0’ and public=’1’"));
foreach($blogs as $blog)
$details = get_blog_details($blog->blog_id);
if($details != false)
$url = $details->siteurl;
$name = $details->blogname;
if(!(($blog->blog_id == 1) && ($show_main != 1)))
$sites[$name] = $url;
$count = count($sites);
$current = 1;
foreach($sites as $name=>$url)
$result.= ‘<a href="’.$url.’">’.$name.'</a>’;
$result.= ($current == $count) ? "n" : ‘ | ‘;
Then scroll down to the end of file and after last occurence of
add_shortcode add your own call:
Update File to save your changes.
Now, whenever anyone use
[network_list] shortcode to in post, page or theme element, a list of network sites will be printed in place of that shortcode.
Of course, you can use this approach to introduce any shortcode to your site and bind any PHP code to it, that will result in doing anything, not just listing your sites.
This WordPress Forum has answer on how to create a shortcode that is available across entire blog network, on all pages, posts etc.
Basically, you have to put your PHP code, that defines your shortcode, to some file placed in
/wp-content/mu-plugins folder. If this folder does not exists in your WordPress installation, simply create it. Read more in this StackOverflow answer or in WordPress Codex.