I am using this function
that gives me a shortcode
I can paste anywhere on the site. It lists all blogs in the multisite network
a user has, but I would like to hide the main site from the list.
Can someone help to adjust the snippet?
-Extra question. - is it possible to show blogs website preview like Facebook?
function show_blog_list() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are not logged in.';
} else {
echo '<h2>Here is your blog list</h2>';
$user_blogs = get_blogs_of_user( $user_id );
foreach ($user_blogs AS $user_blog) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
echo '</ul>';
}
}
add_shortcode( 'bloglist', 'show_blog_list' );
I am using this function
that gives me a shortcode
I can paste anywhere on the site. It lists all blogs in the multisite network
a user has, but I would like to hide the main site from the list.
Can someone help to adjust the snippet?
-Extra question. - is it possible to show blogs website preview like Facebook?
function show_blog_list() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are not logged in.';
} else {
echo '<h2>Here is your blog list</h2>';
$user_blogs = get_blogs_of_user( $user_id );
foreach ($user_blogs AS $user_blog) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
echo '</ul>';
}
}
add_shortcode( 'bloglist', 'show_blog_list' );
Share
Improve this question
edited Jul 30, 2020 at 12:14
Sanfe
asked Jul 30, 2020 at 10:53
SanfeSanfe
11 bronze badge
1 Answer
Reset to default 1I've never used it, but it looks like get_main_site_id
is what you want to figure that out, so therefore your code might look like:
$mainSiteId = get_main_site_id();
foreach ($user_blogs AS $user_blog) {
if ($userblog->site_id != $mainSiteId) {
echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</a></li>';
}
}