Created
January 22, 2020 14:46
-
-
Save agrogeek/b86b5b392ef2e78a95216dd4dc006cbe to your computer and use it in GitHub Desktop.
Add shortcode to list sites in WP Multisite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function make_list_shortcode() { | |
$subsites = get_sites(array('orderby' => 'registered', 'order' => 'DESC' )); | |
if ( ! empty ( $subsites ) ) { | |
$html = '<ul class="subsites">'; | |
foreach( $subsites as $subsite ) { | |
$subsite_id = $subsite->blog_id; | |
$subsite_name = get_blog_details( $subsite_id )->blogname; | |
$subsite_link = get_blog_details( $subsite_id )->siteurl; | |
$html .= '<li class="site-' . $subsite_id . '"><a href="' . $subsite_link . '" target="_blank">' . $subsite_name . '</a></li>'; | |
} | |
$html .= '</ul>'; | |
return $html; | |
} | |
} | |
add_shortcode('list_sites', 'make_list_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment