Skip to content

Instantly share code, notes, and snippets.

@MervinHernandez
Created April 1, 2020 17:35
Show Gist options
  • Save MervinHernandez/17d42dc921bab343b08f5beaf5bf9347 to your computer and use it in GitHub Desktop.
Save MervinHernandez/17d42dc921bab343b08f5beaf5bf9347 to your computer and use it in GitHub Desktop.
TOGGLE WP Admin Notices
<?php
// -- Header - TOGGLE Hide Admin Notices
// -- -- ADD Script and Styling
function wm_admin_notices_toggle_script() { ?>
<!-- JS for Admin Notices Hide -->
<script>
function toggle_visibility(className) {
//alert ('you clicked it');
elements = document.getElementsByClassName('notice');
for (var i = 0; i < elements.length; i++) {
elements[i].style.display = elements[i].style.display == 'block' ? 'none' : 'block';
}
}
</script>
<!-- Style for Admin Notices Hide -->
<style>
.notice {display:none;}
#wpadminbar #wp-admin-bar-notices .ab-icon:before {
content: "\f348";
}
</style>
<?php }
add_action( 'admin_head', 'wm_admin_notices_toggle_script' );
// -- -- ADMIN BAR Toggle Button to show Admin Notices
function wm_admin_notices_toggle_button( \WP_Admin_Bar $bar )
{
$bar->add_menu( array(
'id' => 'notices',
'title' => '<span class="ab-icon"></span>'.__( 'Show Admin Notices', 'wingman-avionics' ),
'href' => '#',
'meta' => array(
'target' => '_self',
'title' => __( 'Toggle showing admin notices on off', 'wingman-avionics' ),
'onclick' => 'toggle_visibility()'
),
) );
};
add_action( 'admin_bar_menu','wm_admin_notices_toggle_button', 910 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment