Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide annoying notifications after each upgrade of Yoast SEO plugin and others admin notices
<?php if (!defined('ABSPATH')) die('Restricted Area');
/*
* Plugin Name: Disable Yoast SEO Notifications
* Description: Hide annoying notifications after each upgrade of Yoast SEO plugin and others admin notices.
* Version: 1.1
* Author: Aurélien Denis
* Author URI: https://wpchannel.com/
*/
add_action('admin_init', 'wpc_disable_yoast_notifications');
function wpc_disable_yoast_notifications() {
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
}
}
@kjprince

This comment has been minimized.

Copy link

kjprince commented Sep 17, 2015

Thanks for this.

@joshuaiz

This comment has been minimized.

Copy link

joshuaiz commented Sep 18, 2015

Yesssss. Thank you. They are just getting more and more annoying. What is wrong with the Yoast people?

@nutsandbolts

This comment has been minimized.

Copy link

nutsandbolts commented Nov 30, 2015

My dashboard is a much better place now. Thank you!

@dbaritchi

This comment has been minimized.

Copy link

dbaritchi commented Mar 3, 2016

@wpchannel - awesome. Is there a way to also disable the Yoast SEO "pointers" in the same manner? one option is to empty his file plugins/wordpress-seo/admin/class-pointers.php file, but that's overwritten with every plugin update, so not ideal.

Thanks!!

@bryanwillis

This comment has been minimized.

Copy link

bryanwillis commented Mar 14, 2016

@dbaritchi I think this might work:

add_action( 'admin_init', function() {
  update_user_meta( get_current_user_id(), 'wpseo_ignore_tour', true );
}, 999);
@chrisblakley

This comment has been minimized.

Copy link

chrisblakley commented Apr 21, 2016

Thanks for this!

@eventideMark

This comment has been minimized.

Copy link

eventideMark commented Apr 21, 2016

I'm not very familiar with adding custom code, but I'm ridiculously familiar with that annoying notification! :) I'm assuming I create a file with the name "mu-plugin-yoast-seo-disable-notifications.php" (or does the name of the file not matter?), but where do I put the file - i'm using a child version of a theme.

@robinbastien

This comment has been minimized.

Copy link

robinbastien commented Apr 22, 2016

YES! Thanks very much!

@garvs

This comment has been minimized.

Copy link

garvs commented Apr 25, 2016

to @eventideMark:
If you put this file to wp-content/mu-plugins folder, it will work as a 'must use' plugin.

@zamson

This comment has been minimized.

Copy link

zamson commented May 12, 2016

Thanks!

@MarcWoodyard

This comment has been minimized.

Copy link

MarcWoodyard commented Jun 1, 2016

52949916

@DustinWStout

This comment has been minimized.

Copy link

DustinWStout commented Jun 5, 2016

Amazing! Quality of life = IMPROVED.

@MC1171611

This comment has been minimized.

Copy link

MC1171611 commented Jun 7, 2016

You're awesome!

@wpchannel

This comment has been minimized.

Copy link
Owner Author

wpchannel commented Jun 12, 2016

Thanks everyone!

@austinginder

This comment has been minimized.

Copy link

austinginder commented Jun 14, 2016

The latest version of Yoast SEO 3.3.0 includes some red unread messages like so: https://cloudup.com/cUu0wFjPHRT. Any ideas how to remove those?

@austinginder

This comment has been minimized.

Copy link

austinginder commented Jun 14, 2016

Ok this might be a pretty hack/slash way but I was able to modify the title within the wpseo-menu admin menu using the following code.

// Remove Yoast SEO nag alert
add_action( 'wp_before_admin_bar_render', 'remove_yoast_counter_admin_bar' );
function remove_yoast_counter_admin_bar() {
    // If Yoast plugin active
    if (is_plugin_active('wordpress-seo/wp-seo.php')) {
        global $wp_admin_bar;
        // Select Yoast admin menu node
        $node = $wp_admin_bar->get_node('wpseo-menu');

        // Finds start of Yoast counter within the title
        $pos = strpos($node->title, '<div class="wp-core-ui wp-ui-notification yoast-issue-counter">');

        // Remove Yoast counter html from title
        $node->title = substr($node->title, 0, $pos);

        // Updates the Yoast admin menu
        $wp_admin_bar->add_node( $node );
    }
}

Or maybe a CSS injection would be cleaner

// Remove Yoast SEO nag alerts
add_action('wp_head', 'remove_yoast_counters');
add_action('admin_head', 'remove_yoast_counters');
function remove_yoast_counters() {
    // If Yoast plugin active
    if (is_plugin_active('wordpress-seo/wp-seo.php') and is_user_logged_in()) {
        echo '<style>
        #wpadminbar .yoast-issue-counter {
          display: none;
        } 
        #adminmenu li#toplevel_page_wpseo_dashboard .awaiting-mod span,
        #adminmenu li#toplevel_page_wpseo_dashboard span.update-plugins span {
            display: none;
        }
        </style>';
    }
}
@wpchannel

This comment has been minimized.

@leesaenz

This comment has been minimized.

Copy link

leesaenz commented Nov 18, 2016

@wpchannel I think @austinginder's code is better than your suggestion because your suggestion removes the entire Yoast menu form the admin bar, whereas @austinginder simply removes the alert bubbles and keeps the menu.

Also, the main code above in this gist doesn't work anymore.

@Bobz-zg

This comment has been minimized.

Copy link

Bobz-zg commented Feb 15, 2017

Thanks. I used to love this plugin before they start BS with UI.

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 5, 2019

Anyone has an idea how to remove the notices generated by wordpress-seo/admin/watchers/class-slug-change-watcher.php? I opened a ticket to have the notices removed but yoast with their uppity refused. Yoast/wordpress-seo#11520

@Interinactive

This comment has been minimized.

Copy link

Interinactive commented Apr 21, 2019

@matto15 this is what I use to hide all of the Yoast crap continually popping up:

	add_action('admin_head', 'adminStyles');
	function adminStyles() {
	  echo '<style>
		.yoast-alert {
			display: none !important;
		}
	  </style>';
	}
@ghost

This comment has been minimized.

Copy link

ghost commented Apr 21, 2019

@Interinactive. Thanks. I will give it a try.

@emcniece

This comment has been minimized.

Copy link

emcniece commented Sep 27, 2019

September 2019 checking in, @Interinactive's comment works wonders 👍

@trivendor

This comment has been minimized.

Copy link

trivendor commented Oct 10, 2019

There are two areas that could really use being addressed - when using Yoast Premium without activation (which may or may not be within intent of this thread)

  1. on plugins page -- yoast makes HTTP calls to headquarters
  2. in yoast seo meta box in post editor -- it loads a warning box using javascript that craftfully loads after everything else so that CSS display none won't work. the js itself is so convoluted that only an expert could unravel it.

would appreciate ideas/fixes for these, thanks

@Interinactive

This comment has been minimized.

Copy link

Interinactive commented Oct 10, 2019

@trivendor How do you make it appear for #2? It's probably not very hard to get around it, but I need to see what you're referring to.

@trivendor

This comment has been minimized.

Copy link

trivendor commented Oct 10, 2019

@Interinactive -- thanks for responding, if you go to any post/page/cpt post editor page, there is the Yoast SEO meta box area that features things like snippet editor etc.

Yoast js loads a yellow nag about subscribing
this comes out of wp-seo-premium-metabox-1160.min.js and is likely tied to other js somehow
using CSS display none for the div doesn't work - either because of something in the javascript or that it loads CSS after the admin css or ?
yoast-yellow

@wpchannel

This comment has been minimized.

Copy link
Owner Author

wpchannel commented Oct 10, 2019

Hi there, I'm the author of the Gist. Since I'm no more using Yoast (I prefer SEOPress with no ads), I can't help you anymore...

@Interinactive

This comment has been minimized.

Copy link

Interinactive commented Oct 10, 2019

@trivendor Still works here. You need to find the name of the div, eg:

https://i.imgur.com/z7CS3yg.png

Then amend the code to include that class:

	add_action('admin_head', 'adminStyles');
	function adminStyles() {
	  echo '<style>
		.yoast-alert,
	        .MetaboxWarning__WarningBox-gHrSIw {
			display: none !important;
		}
	  </style>';
	}

Works perfectly

@trivendor

This comment has been minimized.

Copy link

trivendor commented Oct 10, 2019

Nice ! People do need to be aware that each instance adds a variable string... -gHrSIw is not universal and another string will be used.

But this works great, thanks

@Interinactive

This comment has been minimized.

Copy link

Interinactive commented Oct 10, 2019

Yep that's right. And even if they randomised them with each page load, you could still use certain selectors to catch it. Eg: 'container-name + div', and so on.

@emcniece

This comment has been minimized.

Copy link

emcniece commented Oct 10, 2019

If this plugin has any semblance of packaging or CI build processing (which is almost certainly has) then this CSS class will not only change between versions, it could also differ between installations. I've inspected the last 4 versions of this plugin and can't find gHrSlw anywhere, likely because I'm only looking at the free versions.

This gist should be converted to a plugin, and the nags should be removed by finding and overriding the injecting hooks instead of somewhat-fragile CSS if possible. I'll try and take a stab at this over the weekend... I'm sure @wpchannel wouldn't mind receiving fewer notifications 😂

@trivendor if you have a second, could I ask you to reach out to me at emcniece@gmail.com? I've got a question about the plugin version you currently have.

For now, you might consider using CSS wildcard selectors for slightly longer-term relief (untested concept):

add_action('admin_head', 'adminStyles');
function adminStyles() {
  echo '<style>
    .yoast-alert,
    div[class*='MetaboxWarning__WarningBox-'] {
        display: none !important;
    }
  </style>';
}
@trivendor

This comment has been minimized.

Copy link

trivendor commented Oct 11, 2019

Hi @emcniece yes the string gHrSlw will change to something else - you'd have to look at the generated css when installed and change snippet accordingly. I will try the div without the exact string next go around but it is working with the edit of my particular instance.

regards

@wpchannel

This comment has been minimized.

Copy link
Owner Author

wpchannel commented Oct 14, 2019

Hi there,

I've found an old mu-plugin in my computer if you wan to try a more complet solution:

`<?php include_once(ABSPATH . 'wp-admin/includes/plugin.php');
if (is_plugin_active('wordpress-seo/wp-seo.php')) {

/* Remove HTML Comments */
add_action('get_header',function() { ob_start(function ($o) {
return preg_replace('/\n?<.*?Yoast SEO plugin.*?>/mi','',$o); }); });
add_action('wp_head',function() { ob_end_flush(); }, 999);


/* Disable Yoast SEO Notifications */
function ntp_disable_yoast_notifications() {
	remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
	remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
}
add_action('admin_init', 'ntp_disable_yoast_notifications');


/* Yoast SEO Low Priority */
function ntp_yoast_bottom() {
	return 'low';
}
add_filter('wpseo_metabox_prio', 'ntp_yoast_bottom');


/* Disable screen after update */
function ntp_filter_yst_wpseo_option($option) {
	if (is_array($option)) { 
		$option['seen_about'] = true; 
	}
	return $option;
}
add_filter('option_wpseo', 'ntp_filter_yst_wpseo_option');


/* Remove Node in Toolbar */
function ntp_remove_yoast_bar($wp_admin_bar) {
	$wp_admin_bar->remove_node('wpseo-menu');
}
add_action('admin_bar_menu', 'ntp_remove_yoast_bar', 99);

} ?>`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.