Tuck Admin Notices Into a Collapsible Panel
Gathers the banners plugins print at the top of admin screens into one "Notices" panel that stays closed until you open it, while errors and your own save messages stay visible.
Opens WPIDE on
Code
add_action( 'admin_footer', function () {
?>
<style>
#wpide-notices-panel{margin:12px 20px 0 2px}
#wpide-notices-panel summary{cursor:pointer;color:#2271b1;font-weight:600}
#wpide-notices-panel[open] summary{margin-bottom:8px}
</style>
<script>
( function () {
var wrap = document.querySelector( '#wpbody-content .wrap' );
if ( ! wrap ) { return; }
var notices = Array.prototype.filter.call(
document.querySelectorAll( '#wpbody-content > .notice, #wpbody-content > .updated, #wpbody-content > .update-nag, #wpbody-content .wrap > .notice, #wpbody-content .wrap > .updated' ),
function ( el ) {
return ! el.classList.contains( 'notice-error' ) && ! el.classList.contains( 'error' ) && ! el.classList.contains( 'notice-success' ) && ! el.classList.contains( 'inline' ) && ! el.id.match( /^(message|setting-error-settings_updated)$/ );
}
);
if ( notices.length < 2 ) { return; }
var panel = document.createElement( 'details' );
panel.id = 'wpide-notices-panel';
var summary = document.createElement( 'summary' );
summary.textContent = 'Notices (' + notices.length + ')';
panel.appendChild( summary );
notices.forEach( function ( el ) { panel.appendChild( el ); } );
wrap.parentNode.insertBefore( panel, wrap );
} )();
</script>
<?php
} );
Notes
Success messages after saving and notices marked as errors are never hidden.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.