I want to display the One website url in other site posts and visa versa. So I am trying to use switch_to_blog()
but not able to get the other webite url in the concept of multisite in Wordpress.
I want to display the One website url in other site posts and visa versa. So I am trying to use switch_to_blog()
but not able to get the other webite url in the concept of multisite in Wordpress.
1 Answer
Reset to default 0if you want to display the One website url in other site's posts at bottom. you can use below code. it will display all other site links excepts current site of multisite at end of post content of "post" post type. you can change post type as your need.
add_filter('the_content','add_site_url_in_bottom',10,1);
function add_site_url_in_bottom($content)
{
global $post;
if ($post->post_type == 'post') {
if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
$args = array(
"site__not_in" => get_current_blog_id(),
);
$sites = get_sites($args);
$content .= '<h3>Other Site URLS</h3>';
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
$content .= 'site url : <a href="'.get_site_url($site->blog_id).'">';
$content .= get_bloginfo( 'name' );
$content .= '</a><br>';
restore_current_blog();
}
}
}
return $content;
}
see https://prnt.sc/p9pr4z for reference.