Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save developer-anuragsingh/ca98ee5e3c967f9ec5daa67388a714a2 to your computer and use it in GitHub Desktop.

Select an option

Save developer-anuragsingh/ca98ee5e3c967f9ec5daa67388a714a2 to your computer and use it in GitHub Desktop.
Show menu of parent site in all multiple sites
// All sub-site drop down display
if (!function_exists('get_all_multisite_links')) {
function get_all_multisite_links($menu_name = 'Primary')
{
global $blog_id;
$current_blog_id = $blog_id; // Get current blog id
switch_to_blog(1); // change blog to 'parent site' (ID = 1)
$primaryNav = wp_get_nav_menu_items($menu_name);
$menu_object = wp_get_nav_menu_object($menu_name);
?>
<h2 class="widget-title mb-3">
<?php
echo $menu_object->name;
?>
</h2>
<div class="selectDesti position-relative">
<select id="select" class="custom-select">
<?php
echo '<option value="">--' . $menu_object->name . '--</option>';
foreach ($primaryNav as $navItem) { ?>
<option value="<?php echo $navItem->url; ?>"><?php echo $navItem->title; ?></option>
<?php }
switch_to_blog($current_blog_id); // re-assign current blog value
?>
</select>
</div>
<script>
jQuery(document).ready(function() {
jQuery('#select').change(function() {
location.href = jQuery(this).val();
});
});
</script>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment