WordPress multisite – switching blog by blogid and show content of specified blogid
- Saturday, 28 July 2018 17:03
- Aadil P.
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
echo 'You switched from blog ' . $switched . ' to 7';
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/