-
-
Save zytzagoo/05743e970a3a717d23d7 to your computer and use it in GitHub Desktop.
<?php | |
add_action( 'admin_init', function() { | |
if ( class_exists( 'Yoast_Notification_Center' ) ) { | |
$yoast_nc = Yoast_Notification_Center::get(); | |
remove_action( 'admin_notices', array( $yoast_nc, 'display_notifications' ) ); | |
remove_action( 'all_admin_notices', array( $yoast_nc, 'display_notifications' ) ); | |
} | |
}); | |
thanks too. Yoast was becoming unbearable.
Does anyone have an idea of 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
Please don't anihilate me but I just don't know where this goes. I'm not even a nube but search is so bad you can't find a simple article on how to do this. Paste this into functions.php? Do I add a closing php tag? I searched the github docs but they are all high level, no nube info. Then people rip nubes for asking. :) Can't win. Thanks to anyone who can help.
@Shizart Yes, you can add that into your theme's functions.php (no closing tag). Or you can copy/create the entire file (named however you want) into wp-content/mu-plugins
folder (create one, if it doesn't exist).
Or, perhaps the best route (since above solution worked up to a certain version of wpseo only), just install and use Hide SEO Bloat which actively keeps playing catch-up with Yoast SEO adding more and more unwanted things.
Since Yoast refuses to cut back on the the upsell spam, here's a snippet to remove all the "You trashed a thing! Buy our premium plugin!" notices that they clutter up the admin dashbaord with. Also recommend looking into the Hide SEO Bloat plugin which basically exists solely to remove all the crap that Yoast adds all over your site. Anyway, put this code in your functions.php (or use something like Code Snippets):
/**
* Unbind Yoast's awful constant upsell notifications whenever you trash/delete anything
*
* @ref: https://github.com/Yoast/wordpress-seo/blob/0742e9b6ba4c0d6ae9d65223267a106b92a6a4a1/admin/watchers/class-slug-change-watcher.php#L18
* @see: https://wordpress.stackexchange.com/a/352509
*/
function unbind_yoast_slug_change_watchers()
{
$priority = 10;
$actions_methods = [
'wp_trash_post' => 'detect_post_trash',
'before_delete_post' => 'detect_post_delete',
'delete_term_taxonomy' => 'detect_term_delete',
];
global $wp_filter;
foreach ($actions_methods as $action => $method)
{
if (isset($wp_filter[$action]->callbacks[$priority]) and ( ! empty($wp_filter[$action]->callbacks[$priority])))
{
$wp_filter[$action]->callbacks[$priority] = array_filter($wp_filter[$action]->callbacks[$priority], function($v, $k) use ($method) {
return (stripos($k, $method) === false);
}, ARRAY_FILTER_USE_BOTH );
}
}
}
add_action('plugins_loaded', 'unbind_yoast_slug_change_watchers', 20);
Hopefully this makes things a little nicer for anyone using it.
Make sure to code this as follows:
add_action( 'admin_init', "remove_yoast_notifications");
function remove_yoast_notifications() {
if ( class_exists( 'Yoast_Notification_Center' ) ) {
$yoast_nc = Yoast_Notification_Center::get();
remove_action( 'admin_notices', array( $yoast_nc, 'display_notifications' ) );
remove_action( 'all_admin_notices', array( $yoast_nc, 'display_notifications' ) );
}
}
As a child theme might want to put them back.
Thanks