WordPress multisite – switching blog by blogid and show content of specified blogid


Here is how you can show content from a wordpress multisite parent or another network site on a wordpress multisite network. Recently, I was tasked with a small task on a wordpress mutlisite network.

The client wanted to show the primary menu from the main hq site on all of the network sites, and here is how I was able to implement that.

This involves changing blog by blogid using wordpress function switch_to_blog(); and then restoring the current blog after echoing the needed content.
There is quite a detailed documentation on the official wordpress codex page linked below.

global $switched;
switch_to_blog(7);
echo 'You switched from blog ' . $switched . ' to 7';
restore_current_blog();
echo 'You switched back.';

WordPress Codex link -> https://codex.wordpress.org/WPMU_Functions/switch_to_blog

Read about our other wordpress articles at https://www.aadilprabhakar.in/category/web-devlopment/wordpress/

, ,