WELCOME TO EHOST.COM.NP

Friday, July 8, 2016

How to Make WordPress Admin Notices Actually Dismissible

ads space

WordPress 4.2 introduced a feature where admin notices can now be dismissed / removed from the admin page currently being viewed.

One caveat I discovered was, the dismissal do not persist across pages. That is, when you reload or navigate away from the current admin page to another, you will still see the notice.

I wrote a small library / plugin that elegantly solves this problem which i will be sharing to us. You can easily reuse it in your themes and plugins. And it is also pretty well documented.

Here is a link to the library on GitHub

How to Use it

Update: see the library README for an updated installation and usage guide.

Firstly, install and activate it by cloning / downloading to your WordPress wp-content/plugins directory.

Say you have the following markup as your admin notice

To make it hidden forever when dismissed, add the following data attribute data-dismissible="disable-done-notice-forever" to the div markup like so:

Note: the data-dismissible attribute must have a unique hyphen separated text which will serve as the key or option name used by the Options API to persist the state to the database. Don’t understand, see the following examples.

Examples

Say you have two notices displayed when certain actions are triggered; firstly, choose a string to uniquely identify them. E.g notice-one and notice-two

To make the first notice never appear forever when dismissed, its data-dismissible attribute will be data-dismissible="notice-one-forever" where notice-one is its unique identifier.

To make the second notice only hidden for 2 days, its data-dismissible attribute will be data-dismissible="notice-two-2" where notice-one is its unique identifier and the 2 the number of days it will be hidden.

To actually make the dismissed admin notice not to appear, use the is_admin_notice_active() function like so:

Cool beans. Isn’t it?

ADS SPACE

0 comments:

Post a Comment

Categories

Article How-to All Posts WordPress Android Web design Blogger Plugins CSS Google JQuery Plugins Programming Reviews Web Hosting Blogger Blogging Blogging Tips Tricks Web Development Facebook Git Internet Make Money Online Social Plugins Tips Tips and Tricks Tools Tutorials Windows WordPress Plugins Blogging Tips and Tricks Freebies GSM Google Analytics HTML How To's JavaScript Plugin Development S.E.O SEO SMS SmartPhone Social Media Tips amp; Tricks Top-Most Updates Webmaster Tools Whatsapp Applications Apps Blogger Basics Documentary Downloads Entertainment Gadgets Games Gmail Google AdSense Guest Post IPhone Make Money Blogging SVN Security Softwares Web Hosting Tips and Tricks Wordpress Tips Wordpress Tips and Tricks hostgator iOS Advertising Networks Advertising Technology Affiliates Antivirus Audience amp; Traffic Biography Blog post Blog post Blogger Blogger Errors Blogger Tips Blogger Tools Blogger Widget Blogosphere Bogger Widgets CSS selectors CSS symbols CSS3 Computer amp; Internet Content Writing Coupon Codes Data amp; Analytics Deleted blog Design DoubleClick for Publishers Email and newsletter marketting Email marketing Excel Tips Excel Tips and Tricks Facebook Tricks Feed Feedburner Feedburner subscribers Font Fun GitHub Giveaways Gmail primary inbox Gmail tabs Google sign-in Guides HTML amp; CSS HTML5 Infographics Inspirational Instagram Internet Marketing Internet Tips amp; Tricks Job Listings Knowledge Life Hacks Lists Make-Money Monetization amp; Conversion Monetize Navigation Online Marketing Other PHP Tutorials Passport Publishing amp; Content Quotes RSS Sidebar Smartphones Social Networking Status Tech Tech Blog Technology Telegram Themes UI / UX User Psychology amp; Research VB.Net Web Tools Web browser Widget Windows Tips Windows-10 ad viewability admin notice blogging tools bluehost cherry-pick clone cors custom scrollbar customizer dismissible notices duplicate post feed title git branch git clone gpg gpg2 hybridauth iPad icon font notice responsive wordpress theme same origin policy scrollbar signed git commit smartsvn theme customizer vcs wordpress theme wordpress themes

Blog Archive