I don't understand why this functionality doesn't exist in Wordpress Multisite TBH.

Network Sites Menu Items

I have this working for Custom Menus and the List of Sites on the Nework is working in a Metabox also. However, I would like this to by dynamic like posts, pages, taxonomies, and post type achives on the Admin -> Appearance -> Menus section. Is it possible to change this code so that it acts like a Post, but instead of saying "Custom Link" it says "Site" in the upper right when adding the Menu, and when opening it up, instead of showing the URL as a textbox field, can it just have a hyperlink at the very bottom in the same way that Posts and Pages, etc get displayed when they are added?

Is this possible? I really would like to have these links dynamically created so that if I migrate the site over to another url for each site in the Network, I don't have to edit each of the links in all of the Menus of each of the sites manually.... arggg!

Example code here of it working with Custom Links (just add to functions.php of a multisite theme):

function multisite_add_sites_menu_meta_box($object) {
    if (defined('SUBDOMAIN_INSTALL'))
        add_meta_box('multi-sites-menu-metabox', __('Sites'), 'multi_sites_menu_meta_box', 'nav-menus', 'side', 'default');

    return $object;

function multi_sites_menu_meta_box()
    global $nav_menu_selected_id;
    $walker = new Walker_Nav_Menu_Checklist();

    $current_tab = 'all';
    $publics = array();

    if (isset($_REQUEST['site-tab'])) {

        switch($_REQUEST['site-tab']) {
            case 'publics':
                $current_tab = 'publics';
                $current_tab = 'all';

    // Only want public and/or mature sites, or if no attribute is set!
    $args = array(
        'fields' => '',
        'archived' => 0,
        'spam' => 0,
        'deleted' => 0

    $sites = get_sites($args);

    if (!empty($sites)) {
        foreach ($sites as &$site) {


            $site->classes = array();
            $site->type = 'custom';
            $site->type_label = __('Site');
            $site->object_id = $site->blog_id;
            $site->title = get_bloginfo('name');
            $site->object = 'custom';
            $site->url = site_url(); 
            $site->attr_title = '';

            if (!empty($site->public))
                $publics[] = $site;


    $removed_args = array('action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce');

    echo '
    <div id="sites" class="categorydiv">
        <ul id="site-tabs" class="site-tabs add-menu-item-tabs">
            <li', ($current_tab == 'all' ? ' class="tabs"' : ''), '>
                <a class="nav-tab-link" data-type="tabs-panel-sites-all" href="', (!empty($nav_menu_selected_id) ? esc_url(add_query_arg('site-tab', 'all', remove_query_arg($removed_args))) : ''), '#tabs-panel-sites-all">', __('View All Sites'), '
            <li', ($current_tab == 'publics' ? ' class="tabs"' : ''), '>
                <a class="nav-tab-link" data-type="tabs-panel-sites-publics" href="', (!empty($nav_menu_selected_id) ? esc_url(add_query_arg('site-tab', 'publics', remove_query_arg($removed_args))) : ''), '#tabs-panel-sites-publics">', __('Public Sites'), '
        <div id="tabs-panel-sites-all" class="tabs-panel tabs-panel-view-all ', ($current_tab == 'all' ? 'tabs-panel-active' : 'tabs-panel-inactive'), '">
            <ul id="site-tab-checklist-all" class="categorychecklist form-no-clear">', walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $sites), 0, (object) array('walker' => $walker)), '

        <div id="tabs-panel-sites-publics" class="tabs-panel tabs-panel-view-publics ', ($current_tab == 'publics' ? 'tabs-panel-active' : 'tabs-panel-inactive'), '">
            <ul id="site-tab-checklist-publics" class="categorychecklist form-no-clear">', walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $publics), 0, (object) array('walker' => $walker)), '

        <p class="button-controls wp-clearfix">
            <span class="list-controls hide-if-no-js">
                <input type="checkbox" id="site-tab" class="select-all">
                <label for="site-tab">Select All</label>
            <span class="add-to-menu">
                <input type="submit" ', wp_nav_menu_disabled_check($nav_menu_selected_id, false), ' class="button-secondary submit-add-to-menu right" value="', esc_attr('Add to Menu'), '" name="add-sites-menu-item" id="submit-sites" />
                <span class="spinner"></span>

add_filter('nav_menu_meta_box_object', 'multisite_add_sites_menu_meta_box', 10, 1);

How can I make this change so it's dynamically adjusting the sites urls after migrating to another server? Like posts/pages, etc does.

If I change $site->type and/or site->object to different values other than custom it appears to be a start of this, but than I get error that $_object is not defined in wp-admin/includes/ajax-actions.php within the wp_ajax_add_menu_item function and there doesn't appear to be any filter added for this.

Perhaps there is another way of going about this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.