hide NEW link in admin bar on main site

The "new" link in the admin bar on the main site of our multisite network is useless and confusing to members. Only makes sense to have that on their own sub-sites. Since I can't target a specific site using Ultimate Branding, does anyone have any ideas about how to hide that JUST for the main site?

I thought about trying to add a unique class for the main site to the body tag so that I could target the new link, but I can't figure out where the body classes are generated in the theme.

Any other hacks that might accomplish this?

  • Predrag Dubajic

    Hey @peter_harris,

    Hope you're doing well today :slight_smile:

    I was looking for a class to hide it using CSS in Ultimate Branding but had no luck with that.

    There is a workaround however, below is the code you can use to hide the New tab, you can add this code to your child theme functions.php file or create new .php file in wp-content/mu-plugins/ folder and paste the code with <?php added at start of file.
    If you don't have mu-plugins folder go ahead and create one.

    function remove_admin_bar_links() {
        if( is_main_site() ) {
            global $wp_admin_bar;
            $wp_admin_bar->remove_menu('new-content');      // Remove the content link
        }
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

    Let me know if this works for you.

    Best regards,
    Predrag

  • Adam Czajczyk

    Hey Peter!

    I've tested the code that @Predrag Dubajic gave you on my sandbox WP install and it seems to be working just fine: it hides a "New" link from Network Admin and main site but leaves it intact for all other sites.

    What bothers me here is that despite removing the code from mu-plugins it's sticking somehow. Would it be possible to take a closer look at your site? To do this, I'd need to access your server directly. Would you please send in:

    Subject: "Attn: Adam Czajczyk"

    - your site's WordPress admin login URL
    - admin login and password (may be a temporary account)
    - FTP credentials (hostname, username, password, port number if needed)
    - any other relevant URLs and information
    - link back to this thread

    Please use our contact form here https://premium.wpmudev.org/contact/.
    Select "I have a different question" from the drop-down list.

    Please be sure to make a full backup of your entire site first!

    Cheers,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.