Schlagwort-Archive: Tutorial

Expanded Course: Learn PHP for WordPress

If you’re ready to take your WordPress skills to the next level and get your feet wet with PHP, you’ll love our newly expanded course, Learn PHP for WordPress.

What You’ll Learn

In this course, Envato Tuts+ instructor Rachel McCollin will give you an overview of what PHP is and how it’s used for WordPress themes and plugins, with examples. 

Learn PHP for WordPress screenshot

You’ll go on to learn how to create a PHP file and use it to output HTML. Then you’ll learn to use functions, loops and if statements for coding custom WordPress themes and plugins.

This course has recently been updated with seven new lessons to help you understand the details of PHP and how you can use PHP with WordPress. So dive right in, or watch the introduction below if you want to find out more about it first.

Watch the Introduction



Take the Course

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 460,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

from Envato Tuts+ Code – WordPress


10 Best Ad Manager WordPress Plugins

It wasn’t very many years ago when everyone was trying to make a quick buck on a blog. Fast-forward just a few years, and the entire scene has changed radically.

Selling advertising on a website isn’t as easy as it once was. The „Golden Age of Blogging“ has certainly passed, but that doesn’t mean monetization has come to an end. It simply requires more effort on behalf of publishers and content creators.

Whether you’re selling ads to a third party or you’re using your platform to promote your own content, a solid advert plugin can make all of the difference. To get you started, here are the 10 best ad manager WordPress plugins from Envato Market:

1. Ads Pro Plugin – Multi-Purpose WordPress Advertising Manager

Ads Pro Plugin – Multi-Purpose WordPress Advertising Manager is one of the best ad manager WordPress plugins you’re going to find.

It’s a full-featured tool that provides plenty of advertising options on the front-end with a robust toolset to manage ads. 

Ads Pro Plugin - Multi-Purpose WordPress Advertising Manager

With over 20 ways to display ads, you’ll also find:

  • 3 billing models
  • 4 payment methods
  • WooCommerce integration
  • language and currency translation
  • random ads, capping option, fully customizable
  • and much, much more!

With helpful support and video guides, your ads will be up and running quickly and easily.

From full online statistics to a useful front-end user panel, the Ads Pro Plugin – Multi-Purpose WordPress Advertising Manager is the ultimate in ad manager WordPress plugins.

2. WP PRO Advertising System – All In One Ad Manager

The WP PRO Advertising System – All In One Ad Manager is one of the more robust ad manager WordPress plugins.

It not only includes all the features you would want from an ad manager, it also includes a visual banner designer.

WP PRO Advertising System - All In One Ad Manager

Features include:

  • schedule ads
  • target user tools
  • banner click heatmap
  • supports all major ad networks
  • ad buyers can purchase, manage, and edit ads
  • pay/click, pay/view, and pay/day billing contract options
  • and much, much more

From ad sales to ad designs, this turnkey solution is ready to get any WordPress site up and running with a complete advertising system.

WP PRO Advertising System – All In One Ad Manager is the easy way to manage your advertising.

3. Pro Ads Buy and Sell – WooCommerce

If you already love WooCommerce, you’re going to love the Pro Ads Buy and Sell – WooCommerce plugin.

There’s no feature bloat here—this streamlined solution leverages WooCommerce to sell advertising.

Pro Ads Buy and Sell  WooCommerce

Features include:

  • front-end ad buys and banner uploads
  • payments handled by WooCommerce
  • users can view their own banner statistics
  • and more

Pro Ads Buy and Sell – WooCommerce isn’t just an ad manager for those already running WooCommerce—although very convenient for those that already are. This is a simple ad sales solution that’s viable for anyone looking for something more straightforward.

4. Affiliate Links — WordPress Plugin for Link Shortening and Masking

Not all advertising is about banner ads. If affiliate links are your thing, you need to check out the Affiliate Links — WordPress Plugin for Link Shortening and Masking plugin.

Affiliate Links  WordPress Plugin for Link Shortening and Masking

„Affiliate Links is a premium WordPress plugin that allows you to mask any URL in order to create and shorten any internal or external links.“

Features include:

  • link click stats
  • conditional redirects
  • Google Analytics tracking
  • and more

There’s no need for a robust ad manager WordPress plugin if all you need is to manage affiliate links. This is what you need.

With Affiliate Links — WordPress Plugin for Link Shortening and Masking, take control over your affiliate links with widgets, shortcodes, and more.

5. Advanced Floating Content

Not all types of online marketing and advertising require the same tool.

If content marketing is your game, then Advanced Floating Content is what you want.

Advanced Floating Content

Features include:

  • easy to customize
  • shortcode support
  • float your content in just about any place and any way
  • supports video embedding, social media sharing, HTML code
  • and much more

Don’t let your chance float away—get your online visitors‘ attention using the Advanced Floating Content WordPress plugin.

6. Ad Overlay Anything – Videos, Images or Text

Place your advertising where your web user is looking—videos, images, and text! Ad Overlay Anything – Videos, Images or Text does exactly that, by making it easy to add an overlay over videos, images, or text.

Ad Overlay Anything - Videos Images or Text

„If a visitor to your website is viewing certain content, for example, then they are more likely to be interested in products or services relating to that content. Tailoring your advertisements this way allows you to drastically increase your conversion rates and truly make the most out of your advertising space.“

The Ad Overlay Anything – Videos, Images or Text is simple, straightforward, and highly effective.

7. Popup Banner WordPress Plugin – Float Banners

Popup Banner WordPress Plugin – Float Banners is perfect for quick and simple advertising.

You don’t always need a robust ad manager, so keep it simple with something like a popup banner.

Popup Banner WordPress Plugin - Float Banners

Features include:

  • five banner positions
  • track views, clicks, and CTR
  • customize banner behaviors
  • and more

Setting the minimum width screen width for display is one of the strongest floating banner options. If you don’t want to show banners for those on a mobile device, you can easily stop it from displaying with this feature.

Prepare your jpeg, png, or gif image file and get the Popup Banner WordPress Plugin – Float Banners started.

8. Advert Flap Pro

Advert Flap Pro is one of the most fun ways to display an advert.

It’s stylish, animated, and easy to use. And best of all, it gets your attention.

Advert Flap Pro

„Advert Flap Pro is an animated advert for WordPress sites. It is one of the most effective ways to get a message or advert out to people on your site without the intrusiveness of modals or popups.“

With over 23 styles built in, you can add as many instances as you need, schedule, and only display on specific pages.

Check out Advert Flap Pro. It’s a lot of fun, and if you don’t want it to be animated, the static version is clean and sharp.

9. Banners Rotator Generator For WordPress

Perhaps the best ad manager isn’t a WordPress plugin. Maybe it’s you?

With the Banners Rotator Generator For WordPress, you can set up and manage your own ad spaces.

Banners Rotator Generator For WordPress

Features include:

  • edit all banners
  • customizable parameters
  • WordPress upload system support
  • and more

Banners Rotator Generator For WordPress is a quick, easy, and simple way to add and manage banner ads on any WordPress site.

10. AdBlock Monetizer – WordPress Plugin

An ad manager WordPress plugin won’t help if web users are using AdBlock—blocking revenue-generating advertising.

Fight back with the AdBlock Monetizer – WordPress Plugin!

„This plugin is able to detect adblock software.“

AdBlock Monetizer - WordPress Plugin

The concept is simple:

This plugin allows visitors to view your website content with AdBlock enabled, if they agree to pay. Otherwise, they must disable AdBlock to view your website.

Features include:

  • PayPal support
  • customize price and currency
  • customize period of time the pages are accessible
  • and much more

AdBlock Monetizer – WordPress Plugin not only offers websites some relief from AdBlock, but also educates websites on the real cost of ad blockers.


There are many different ways to monetize your WordPress website with advertising. While a robust ad manager WordPress plugin may very well be the best and most effective way for many, there are still those that would greatly benefit from a unique approach.

Before diving in and purchasing the most robust solution, make a list of what you require and a list of what would be really nice to have but not essential. Once you’ve got this done, review this list and see what solution works best for what you need—and maybe even a few things you want.

Envato Market has many different advertising WordPress plugins that may also be helpful, as well as some great advertising how-to tutorials and a wide variety of helpful eBooks.

What are the most important features you look for in an ad manager WordPress plugin?

from Envato Tuts+ Code – WordPress

10 Best Bitcoin & Cryptocurrency WordPress Plugins

Bitcoin is booming.

In February of 2018, someone bought $400 million worth of Bitcoin. But this isn’t just an isolated instance. While $400 million is certainly newsworthy, the truth of the matter is that Bitcoin and other cryptocurrencies are becoming more mainstream. It feels as if we are at a tipping point of cryptocurrency becoming a legitimate currency recognized internationally or failing miserably. Will millions be made? Or millions be lost?

If you’re keeping up with cryptocurrency, here are the 10 best Bitcoin and cryptocurrency WordPress plugins from Envato Market:

1. CryptoWP – Realtime Cryptocurrency Market Prices on WordPress (PRO)

CryptoWP – Realtime Cryptocurrency Market Prices on WordPress (PRO) is not only one of the best-looking Bitcoin and cryptocurrency WordPress plugins, it’s also one of the most robust. It offers a wide variety of ways to display cryptocurrency market prices. 

CryptoWP - Realtime Cryptocurrency Market Prices on WordPress PRO

„You can convert all coins to supported currencies: USD ($), EUR (€), GBP (£), AUD (A$), CAD (C$), JPY (¥), INR (₹), TRY (₺), ZAR, IDR, KRW.“

Features include:

  • comes with three themes—and supports custom CSS
  • real-time notifications and conversions
  • real-time cryptocurrency updates
  • historical value charts
  • fully customizable
  • and much more!

Line charts, table views, and forms for buy/sell alarms—CryptoWP – Realtime Cryptocurrency Market Prices on WordPress (PRO) is one of the best.

2. Cryptocurrency Charts for WordPress

Another great option for displaying Bitcoin and cryptocurrency charts in WordPress is the Cryptocurrency Charts for WordPress plugin. It boasts more than 2,000 different cryptocurrencies, so you’ll be hard-pressed to find a currency this plugin cannot chart. 

Cryptocurrency Charts for WordPress

„Cryptocurrency Charts for WordPress plugin allows to easily embed fully customizable interactive cryptocurrency charts into a WordPress website.“

Chart types include:

  • line
  • step
  • column
  • candlestick
  • smoothed line

Features include:

  • fully customizable
  • display trading volume
  • historical performance can be compared
  • displays intraday data in 15-minute intervals
  • unlimited charts per page and translation ready
  • and much more

If you want to display Bitcoin and cryptocurrency Charts, you want Cryptocurrency Charts for WordPress.

3. Premium Cryptocurrency Widgets for WordPress

Easily add Bitcoin and cryptocurrency widgets with Premium Cryptocurrency Widgets for WordPress. With more than 1,500 cryptocurrencies supported and major cryptocurrencies updated in real time without a page refresh, this one of the best cryptocurrency widget plugins for WordPress.

Premium Cryptocurrency Widgets for WordPress

„Premium Cryptocurrency Widgets plugin allows you to easily add various types of widgets with live cryptocurrency quotes to your WordPress website.“

Widget types include:

  • box
  • table
  • inline
  • comparison
  • leaderboard
  • spark charts
  • scrolling ticker

The Premium Cryptocurrency Widgets for WordPress plugin includes multiple color themes and includes logos for each of the cryptocurrencies.

If you’re looking for Bitcoin and cryptocurrency widgets, this is what you want.

4. WooCommerce Bitcoin Payments

While Bitcoin has been on the rise for years, using it to make actual purchases is something that has only become more prevalent recently. What better way to jump on the Bitcoin train than to start accepting Bitcoin payments? WooCommerce Bitcoin Payments makes it super easy.

WooCommerce Bitcoin Payments

„With an easy 5 minutes setup you’re ready to take your customer’s bitcoins in your own wallet.“

Supported exchange rate sources:

Features include:

  • translation ready
  • dynamic restrictions
  • automatic payment notification
  • converts any currency your store accepts and converts it to Bitcoin
  • and more

One does not simply start accepting Bitcoin on their WooCommerce website without using the WooCommerce Bitcoin Payments plugin.

5. FAT Coincap – Cryptocurrency WordPress Plugin

Add the latest Bitcoin and 1,300 other cryptocurrencies information with a simple shortcode using the FAT Coincap – Cryptocurrency WordPress Plugin. Adding a cryptocurrency chart, table, comparison, ticker, or leaderboard is made super easy with this easy-to-use plugin.

FAT Coincap - Cryptocurrency WordPress Plugin

„FAT Coincap plugin can be easily configured through the native WordPress admin interface and added to a page, post or widget by copy and paste the shortcode.“

Easily display a:

  • box
  • table
  • chart
  • ticker
  • comparison
  • leaderboard

Features include:

  • compare and view the history of 1, 7, and 30 days
  • supports more than 1,300 cryptocurrencies
  • display an unlimited number of charts
  • real-time update
  • filter results
  • and more

You don’t need to have technical skill or knowledge of HTML or PHP to get the most out of the FAT Coincap – Cryptocurrency WordPress Plugin.

6. Cryptocurrency Price Ticker Widget PRO – WordPress Plugin

Display a live cryptocurrency price ticker with an easy shortcode using the Cryptocurrency Price Ticker Widget PRO – WordPress Plugin.

Cryptocurrency Price Ticker Widget PRO - WordPress Plugin

„You can show top 100+ crypto coins: Current Price, Market Cap, Volume and % Changes (hourly / 24 hours & 7 days)“

Features include:

  • CoineMarketCap + CryptoCompare APIs
  • live price changes
  • shortcode
  • more

Easily add an exciting crypto coin ticker with the Cryptocurrency Price Ticker Widget PRO – WordPress Plugin.

7. Cryptocurrency Prices for WordPress

Display cryptocurrency or altcoin prices using shortcodes with the Cryptocurrency Prices for WordPress plugin. It supports more than 1,300 cryptocurrencies and over 30 exchange currencies, so you’ll be able to display just about any combination of data you like.

Cryptocurrency Prices for WordPress

„Just install it, configure it and let it run.“

Features include:

  • customizable display
  • unlimited displays
  • filterable results
  • icons include
  • no API key
  • and more

You’ll also find mobile support and included sprite logos for SEO optimization.

Cryptocurrency Prices for WordPress is one of the best.

8. BitCoin | Crypto | Crypto Currency | Widget Shortcode Collection For WordPress

This isn’t just another chart, that uses another shortcode, for your typical cryptocurrency widget. This is a mega pack of useful widgets. The BitCoin | Crypto | Crypto Currency | Widget Shortcode Collection For WordPress includes over 24 widgets.

BitCoin  Crypto  Crypto Currency  Widget Shortcode Collection For WordPress

„Easy to use and has the option of preview in the backend. Then you can select the widget and get the code very easily“

Features include:

  • easy to use
  • easy to preview
  • easy to get your shortcode

You can also create your own layouts using custom styles and CSS.

With over 24 different widgets, you’re sure to find the widget you need. Learn more about BitCoin | Crypto | Crypto Currency | Widget Shortcode Collection For WordPress.

9. Cryptocurrency Mining Calculator Widgets for WordPress

Easily add a cryptocurrency mining calculator to your WordPress website with a simple shortcode. The Cryptocurrency Mining Calculator Widgets for WordPress is insanely accurate, as it includes estimated ROI, maintenance fees, and more.

Cryptocurrency Mining Calculator Widgets for WordPress

„Cryptocurrency Mining Calculator Widgets plugin allows you to easily add various types of cryptocurrency mining calculator widgets to your WordPress website.“

Features include:

  • fully responsive and unlimited colors
  • supports multiple currencies
  • exact calculations
  • and more

Cryptocurrency Mining Calculator Widgets for WordPress is the perfect addition to any Bitcoin and cryptocurrency website.

10. CryptoIcons – Ultimate Cryptocurrency Icons Kit

Easily add 281 different cryptocurrency icons in the WordPress WYSIWYG editor. Simply add the CryptoIcons – Ultimate Cryptocurrency Icons Kit plugin—it’s that easy.

CryptoIcons - Ultimate Cryptocurrency Icons Kit

„CryptoIcons include over 280 high quality vector icons, ready-to-use on your site. Easy to resize, easy to change color, easy to use!“

Features include:

  • vector icons for pixel-perfection
  • easy shortcode generation
  • easy to use

If your WordPress website is all about Bitcoin and cryptocurrencies, you need to be all about getting the CryptoIcons – Ultimate Cryptocurrency Icons Kit plugin.


With the recent boom of cryptocurrencies and Bitcoin becoming more mainstream, the demand for more Bitcoin and cryptocurrency WordPress plugins has seen a sharp increase.

Envato Market has many other great Bitcoin and cryptocurrency plugins for WordPress. However, if you don’t see exactly what you’re looking for, you can always consider coding your own solution. There are several great WordPress Code TutorialsCode Courses, or eBooks available on Envato Tuts+ that are worth checking out.

from Envato Tuts+ Code – WordPress

WordPress Live: Code a Child Theme

Child themes are a great way to customize an existing WordPress theme. You can add styling and functionality that the original theme designer never thought of, and you don’t have to worry about losing your changes when the theme updates!

In this free live stream course, Rachel McCollin will show you how to take a professional WordPress theme and customize it to fit your brand. She’ll be coding live, so you can follow along on YouTube and ask questions as we go.

Watch the course live to ask questions as you follow along!

If you can’t make it to the live stream, you always can watch the recorded course later on Envato Tuts+.

from Envato Tuts+ Code – WordPress

Persisted WordPress Admin Notices: Part 4

So far in this series, we’ve covered two separate ways to dismiss persistent WordPress admin notices. We’ll build on that in this fourth and final part of the tutorial series by looking at two more specific methods to permanently dismiss your admin notices. We’ll round things off by showing how to create your own custom admin notice types and add decorations such as icons.

Sticky Admin Notice

We already know how to display an admin notice that can be dismissed. All we have to do is add the is-dismissible CSS class to the containing div element. However, this is only temporary and will only dismiss the notice for the current page. As soon as the page reloads, it reappears again.

To make it permanently dismissible involves more code than we’ve seen so far, but it isn’t too difficult to implement. Let’s take a look at what’s involved, starting with an overview.

We’ll use a custom option to store the display status of our admin notice. On plugin activation, this option will be created/updated and set to true. The admin notice will then only display if the option is currently true.

The key to this method is using Ajax to allow us to set the option to false when the dismiss button is clicked. Once successfully set to false, the conditional code that checks the option status will fail, and the admin notice will no longer be displayed.

Let’s begin by adding the admin notice itself, which will be a plain notice to begin. In Gwyer_Dismissible_Admin_Notices::init(), add a new add_action call:

Then add the dismiss_admin_notice() callback function to the same class:

This adds an admin notice that displays only on the plugin admin page and is very similar to what we’ve seen in previous tutorials. The only slight difference here is that we’ve also added a CSS ID to the admin notice div container. This will be used to specifically target the admin notice we’re interested in.

Standard admin notice with custom CSS ID

We’ll need to add JavaScript code to make the Ajax call work, so add a js folder in the root admin-notices plugin folder and inside create a file called admin-notices.js. Add code to the new file to test it’s loading properly by outputting a console message.

In Gwyer_Plugin_Options::init(), add a new add_action call to enqueue our script file:

We only want this JavaScript file to be loaded on the plugin options page, so we need a way to conditionally enqueue it. We can do this by checking what admin page we’re currently on to see if it’s our plugin options page.

We can get a handle to our plugin options page by storing the return value of add_options_page() in a class property. We had no need of this value previously, so we just called add_options_page() without storing the return value.

Add a class property to Gwyer_Plugin_Options:

Then, in create_admin_menu_page(), use this new property to store the handle to our plugin options page:

We can finally enqueue our JavaScript file so that it loads only on the plugin options page:

If all went well then you’ll see an admin-notices.js loaded! message outputted to the browser console.

Admin notice JavaScript loaded

Update the JavaScript code in admin-notices.php to the following:

Here, we’re listening for a click event on the an1 CSS ID we added to our admin notice earlier. As soon as it’s clicked, an Ajax request is fired. Let’s handle that request next.

In Gwyer_Dismissible_Admin_Notices::init(), add a new add_action call:

This will run the callback function once the display_dismissible_admin_notice Ajax request fires. Remember that this originally was defined as the data.action property in our Ajax request.

Now add the display_dismissible_admin_notice callback function to Gwyer_Dismissible_Admin_Notices:

Save your changes, reload the plugin options page, and click the admin notice dismiss button to see the Ajax request in action!

The Ajax request in action

If the request was successful then you’ll see a Processing Ajax request… DONE! message displayed in the browser console.

The final piece of the puzzle is to create a custom option initially set to true but which is then set to false when the dismiss button is clicked. Then, when the plugin options page loads, the admin notice only displays if the custom option value is true.

In Gwyer_Dismissible_Admin_Notices::init(), add a second call to register_activation_hook():

And add the create_custom_option callback function to the class:

Now, when the plugin is activated, a custom option called gwyer-dismiss is created and set to true.

Update display_dismissible_admin_notice() to update our custom option when the Ajax request fires:

Now all that’s left to do is update dismiss_admin_notice() to check for the value of the custom option and only render the admin notice if it is set to true.

Deactivate and reactivate the plugin to test the code we’ve added. Visit the plugin options page, dismiss the admin notice, and refresh the page. The notice should no longer be visible. Yay!

Because the custom option is set to true every time the plugin is activated, you can repeat the above steps to test the dismissible admin notice as many times as you like.

To keep things simple, this was a bare-bones example of using an Ajax request to set the custom admin notice option. In practice, you’d want to use a nonce (number used once) value to validate the Ajax request as a minimum security measure.

This was a lot of work to just permanently dismiss an admin notice, but the final effect works well and is something you can use to good effect in your own plugins.

Custom Action Admin Notice Dismissal

It’s time to look at a slightly different method for dismissing admin notices now. This is a nag type of admin notice that displays on all admin screens and can’t be dismissed until some action has been performed.

Note: Use this method with caution or you’ll risk alienating your plugin users very quickly!

The specific action we’ll focus on in our example will be to display an admin notice until a required plugin or list of plugins have been installed and activated.

Unlike the previous method where we had to jump through hoops to get an admin notice to be permanently dismissible, the solution for this method is refreshingly simple!

First, comment out all the function calls in Gwyer_Dismissible_Admin_Notices::init(). Then, add a new add_action() function:

And define the callback as follows:

That’s all there is to it! I told you it was simple, didn’t I?

The only thing we did differently this time was to use the is_plugin_active() WordPress function to test if the Hello Dolly plugin is installed and activated. If not, is_plugin_active() will return false, and our admin notice will be displayed.

Example of a nag admin notice

Try activating the Hello Dolly plugin to verify the admin notice goes away.

This works well for single plugins, but what if you wanted to remind users to activate multiple plugins? Instead of hard-coding in the Hello Dolly plugin information, we could create an array to whitelist our required plugins.

Replace install_plugin_to_dismiss_admin_notice() with:

The required plugins are now stored in an array which is looped over to check if each plugin has been activated. For any plugin not currently active, the name is added to a $requires_activating array which is outputted via the admin notice as a comma-separated list of required plugin names.

List of required plugins

Custom Admin Notices

Before we finish, let’s have a little fun by creating our own custom admin notice types. Let’s see how to add some custom admin notice types of our own. By now you’ll be fully familiar with the four built-in admin notices WordPress provides by default, but it’s not that difficult to come up with some of our own.

First, though, comment out all function calls in Gwyer_Dismissible_Admin_Notices::init() so we start out on a clean slate.

We’ll need to add CSS for our custom admin notice types, so in the root plugin folder add a css folder, and inside create a file called admin-notices.css. To enqueue it on all admin pages, add a new add_action call in Gwyer_Plugin_Options::init().

Then, for the enqueue_styles() callback, add this method to the same class:

Now let’s set up a new method to output our custom admin notices. In Gwyer_Admin_Notices::init(), add:

Then add a callback to display a series of custom admin notices:

Finally, add CSS to admin-notices.css to style our custom admin notices:

After you save the changes, load any admin page to see our custom admin notices.

Some examples of custom admin notices

Judging by the results, it’s probably a good idea to use custom admin notices sparingly, otherwise you’ll run the risk of them looking garish. 

I won’t go into details about the custom CSS used. It’s just for a bit of fun, and most of the styling is pretty self-explanatory.

We used dashicons font icons for our custom admin notices for convenience as they are available in the WordPress admin by default. But you could import and use any icons you like for extra decoration.

Try the Code for Yourself

All the code from this tutorial series has been wrapped up in a WordPress plugin for you to download. Take a look at the code, extend it, and implement new ways to display (and dismiss) admin notices. Be sure to let me know in the comments if you create something cool! I’d love to see what you come up with.


Thank you for joining me in this four-part tutorial series. Hopefully you’ll now have a lot more confidence in how you implement admin notices in your own projects.

We’ve covered many different aspects of WordPress admin notices, including multiple ways of permanently dismissing them, which isn’t possible without custom code.

Creating your own custom admin notices is pretty easy too, but in practice you’d want to use them sparingly in your own projects. Most of the time it’s best to keep to the default WordPress styles for a consistent user experience.

WordPress has an incredibly active economy. There are themes, plugins, libraries, and many other products that help you build out your site and project. The open-source nature of the platform also makes it a great option from which you can better your programming skills. Whatever the case, you can see what we have available in the Envato Market.

And don’t forget to download the plugin and play around with the code. It’s a great way to get more familiar with how all the pieces fit together. And please let me know your thoughts on the tutorial via the comments below.

from Envato Tuts+ Code – WordPress

Persisted WordPress Admin Notices: Part 3

Welcome back to our series on persisted WordPress admin notices. We’re now in a good position to be able to extend our admin notice functionality and control when they appear on the page.

After that, we’ll move on to persistent admin notices and see how you can make sure they’re dismissed in such a way that they don’t reappear when admin pages are reloaded. 

This is particularly important as custom admin notices implemented in plugins and themes are only really useful when you can permanently dismiss them. It’s not enough to simply add the is-dismissible CSS class.

Controlling When Admin Notices Appear

Up until now, all admin notices have been displayed as soon as the page loads. There may be times when this is inconvenient and you want the admin notice to be displayed after a certain event has been triggered instead.

How about if we wanted a custom admin notice to be displayed on the plugin options page we created earlier, but only after the Save Changes button was clicked?

We already know from part two how to restrict an admin notice to the plugin options page. Let’s find out how we can trigger it to appear after plugin options have been saved.

Begin by commenting out the add_action function call for plugin_admin_notice. Then, add a fourth add_action call in init as follows:

Whenever plugin options are saved, a settings-updated value of true is added to the super global $_GET array variable. We can use this to determine if we need to display our admin notice.

Add a new conditional_plugin_admin_notice method to Gwyer_Admin_Notices that outputs the value of $_GET to the screen.

When the plugin options page is loaded normally we don’t see a value set for settings-updated.

Normal Plugin Options Page Loading

Now enter some text in the Enter some text field and click Save Changes. This time, we see settings-updated set to true, which we can put to good use.

The settings-updated value set to true

Replace the conditional_plugin_admin_notice with:

By now, this code should be looking familiar to you. A couple of new features have been added, though. Firstly, the conditional expression has been extended to test for the presence of settings-update. Now, the admin notice will only display if we’re on the plugin options page and if settings-updated is set to true.

Also, the current user display name is outputted to make the admin notice a little more personal.

A more personal admin notice message

The wp_get_current_user() function returns information about the currently logged-in user. This object is stored in $current_user and contains details such as user email, ID, first name, last name, and display name, which is the particular property we’re interested in.

Finally, for a little extra polish, we’ve prevented the default admin notice from displaying so our custom one is the only one visible to the user. To achieve this, we just added a single line of code to conditional_plugin_admin_notice() to output CSS to hide the unwanted admin notice.

The final result when plugin options are saved is shown below.

The finished admin notice to show the plugin has been updated

While this works fine for demonstration purposes, a better (and cleaner) approach would be to add styles to a separate style sheet instead and enqueue it on the plugin options page only.

Our custom admin notice could be extended even further in a number of ways. One possibility could be to maintain a log that stored the current date/time along with user information every time the plugin options were saved.

Or how about getting the admin notice to display how many times the plugin options have been saved that day, week, month, etc.? I’m sure you can think of more examples too!

Dismissing Persisted Admin Notices Effectively

It’s time to get our hands dirty now and dig into more in-depth code as we turn our attention to dismissing persistent admin notices. Up until now, the only way we’ve seen how to do this is to add the .is-dismissible CSS class to our admin notice div container. This dismisses the admin notice for the current page, but it isn’t much use in practice as it reappears when an admin page is reloaded.

So how can we fix this? We’ll look at several different methods of dismissing persistent admin notices, including:

  • One-off admin notice that disappears after one view.
  • An admin notice counter that disappears after a certain number of views.
  • Sticky admin notice that remains dismissed upon page refresh.
  • Custom action dismissal (admin notice removed after specific action has completed).

Before we start implementing each of these examples, make sure all add_action() calls in Gwyer_Admin_Notices::init() have been commented out. Then add a new dismissible-admin-notices.php file to the admin_notices plugin folder. Open up this new file and add a new class definition:

In admin_notices.php, add another require_once() call to import our new class:

The Gwyer_Dismissible_Admin_Notices class will contain all code related to dismissing persisted admin notices.

One-Off Admin Notice

The first method we’ll look at is how to display an admin notice just the once so it doesn’t reappear on page load. You could use this method to notify a user when a plugin or theme has just been activated.

Let’s do this for our Admin Notices plugin. We’ll start by registering a WordPress transient option upon plugin activation that’s set to expire almost immediately.

In the Gwyer_Dismissible_Admin_Notices class, add a call to register_activation_hook():

The register_activation_hook() function requires you to specify the path to the main plugin file, but we’re currently in dismissible-admin-notices.php. So we can’t just use the PHP magic constant __FILE__ we used previously as this always points to the current PHP file.

Instead, we have to build the path to the main plugin file ourselves using plugin_dir_path( __FILE__ ) . 'admin-notices.php'.

When the Admin Notices plugin is activated, it will run code added to a set_admin_notice_transient class method, which we’ll define next.

This method creates a new transient called 'admin-notice-transient' with a value of true, and is set to expire after five seconds.

Let’s make use of this transient by conditionally displaying an admin notice if we’re on the right admin page and our transient still exists.

Add a new add_action() call to init().

Then, add the display_admin_notice callback function as a new class method:

Similarly to previous examples, the admin notice only displays if we are on a specific page—in this case, the main admin plugins page. But we have an additional condition that the 'admin-notice-transient' must also exist, otherwise the admin notice won’t display.

After the admin notice is outputted, the transient is deleted immediately, even though we initially set it to expire after only five seconds. This just ensures that it won’t be shown again. This could potentially happen if a user tried to refresh the plugins page very quickly. But by deliberately deleting the transient, we can be certain this won’t ever be the case.

To test the code we just added, head on over to the main plugins page and deactivate, then reactivate, the Admin Notices plugin.

The one-off admin notice

The key here is the 'admin-notice-transient' transient setting. Without this, the admin notice would appear every time the plugins page loaded (after the plugin was activated), which isn’t what we want.

Admin Notice Counter

Next up is an admin notice that will display a set number of times only, after which it won’t be visible anymore. Also, this time around it won’t be restricted to any particular admin page.

Before we begin, in the Gwyer_Dismissible_Admin_Notices class, comment out the register_activation_hook() and add_action() function calls. Now let’s set up a basic admin notice which we’ll extend the functionality of shortly.

Add a new add_action() call in init():

And then flesh out the callback function display_admin_notice_counter():

This will display a standard admin notice that will appear on every WordPress admin page.

Standard admin notice ready for customisation

Let’s think about what we need to do. Our admin notice should display a set number of times, and each time it appears an internal counter is increased by one. Once the counter limit has been reached, the admin notice shouldn’t appear again.

We want the admin notice to be displayed on any admin page and so the counter value must persist between page loads. One good way of doing this is to use a database option to store the counter value.

Add a counter class property to store the counter limit value:

This will be used shortly to manage how many times the admin notice appears. Inside display_admin_notice_counter(), update the code as follows:

Prior to the admin notice being displayed, we’re retrieving the counter option, and a default value is returned if it doesn’t yet exist. After the admin notice renders, the counter option is increased by one and updated. If it doesn’t exist then a new option will be created to store the current value.

We’ve also updated the CSS class to be an information admin notice.

Try visiting various admin pages and see the counter increase each time.

Counter admin notice in action

The ++$counter code is an example of a pre-increment operator. It adds a value to $counter before it’s saved to the database. If we used a post increment operator (i.e. $counter++) then the value of $counter would be stored first and then increased, which wouldn’t work.

Let’s incorporate $counter_limit now to prevent the admin notice appearing too many times. Add this to display_admin_notice_counter() underneath the declaration for $counter:

Now, once the admin notice has displayed five times, it won’t be visible on subsequent admin pages. It might be nice, though, to display a message the last time the admin notice appears so the user knows it won’t appear again. Extend the conditional expression and output an additional message:

However, you won’t see the message if you’ve already gone over the counter limit. You can temporarily solve this by increasing the $counter_limit variable.

Display an additional message on the final render

For testing purposes, it would be better to be able to reset the counter limit. If you know how to edit the database, you can go in and change the option directly, but this can be tedious to do multiple times. So let’s implement our own reset feature.

First, change $counter_limit back to 5 and add a new class property:

Then, inside init() replace


The reset function should either show our counter admin notice or delete the admin_notice_counter database option and display a warning admin notice instead.

To use the new reset feature, simply change $counter_reset to true and load any admin page.

Reset admin notice counter

Then change it back to false again.

Admin notice counter successfully reset

Note: This method could easily be used to display an admin notice just the once, as we did in the previous example, but it’s slightly more complicated to set up. It really depends on your requirements.

If all you ever need is a single use admin notice then the previous method will probably suit your needs better and is quicker to implement. But the counter method is more flexible, and once set up, it’s just as easy to use in your own projects.


We’ve covered quite a lot of ground in part three of this tutorial series. We’ve seen how to control when admin notices appear rather than just always appearing as soon as an admin page has finished loading. This is useful in many ways, but our example showed how to display a custom admin notice after plugin options had been saved.

Then, we moved on to two distinct examples of dismissing persistent admin notices. This gives you a lot of flexibility in how you present admin notices to the user. And in the next and final part of this tutorial series, we’ll be looking at more ways to dismiss persistent admin notices.

And, for a bit of fun, we’ll create our own custom admin notice types and add icon decorations.

from Envato Tuts+ Code – WordPress

Persisted WordPress Admin Notices: Part 2

In part one of this series, we learned how to implement a basic admin notice that appears at the top of every WordPress admin page. In this tutorial, we’ll start to build out a plugin to contain all our custom admin notice code.

We’ll begin by implementing standard admin notices and use them as a base for more flexible and advanced examples.

Setting Up Our Plugin

First, though, let’s set up a new plugin from scratch that we’ll be using for all our admin notices so we’re ready to start entering code.

I’ll assume here that you already have a local WP development site set up. If not then refer back to the links in part one of this tutorial series.

Create a new plugin folder called admin_notices inside /wp-content/plugins/, and then create an admin_notices.php file which will be the main plugin file.

Open up admin_notices.php in your favorite editor and add the basic plugin structure:

We added a basic plugin header so WordPress recognises our plugin. This is followed by a class that will contain methods to display our admin notices.

I named the class Gwyer_Admin_Notices to try and make it as unique as possible. This way, it’s much less likely to conflict with an existing class name.

Let’s start by displaying a basic admin notice, and then add to it to make it more useful. To create an admin notice, add the admin_notices hook to the init() function:

The hook includes a test_notice callback function which will be used to output the admin notice markup.

Add the following class method to Gwyer_Admin_Notices to display the actual admin notice. For the messages, we’ll be using classic movie quotes from the last 100 years of movies.

Activate the plugin to show the test notice.

Adding a basic admin notice to our plugin

Let’s also add examples of the other types of admin notice we can display including the dismissible type by adding the is-dismissible CSS class. Add these to the test_notice() method underneath the existing admin notice div:

Full set of admin notice types

This is the full array of admin notice types we can display via the WordPress core CSS classes. Remember, though, that the dismissible admin notice will reappear on each page load!

‚Dismissible‘ admin notice in this context means only for the current page. Having persistent admin notices isn’t very flexible, so later on we’ll be specifically looking at different ways you can dismiss your admin notices effectively.

Admin Notice Hooks

So far, we’ve only used the admin_notice hook to implement an admin notice. There are in fact four separate admin notice hooks that you can use to display notifications, but admin_notice is the one most commonly used.

The four hooks available are:

*No official documentation currently available for these hooks.

So where would you typically use all_admin_notices, user_admin_notices, and network_admin_notices? And how do they differ from admin_notices?

I said previously that the admin_notices hook displays notifications on all admin pages, but this isn’t strictly true. If you take a look at admin-header.php in WordPress core, you’ll see that admin_notices, network_admin_notices, and user_admin_notices are mutually exclusive. That is, only one of these hooks fires on a WordPress admin page.

A series of conditional expressions evaluates the current admin page and fires just one of them depending on the type of admin page you’re currently on.

Firstly, is_network_admin() checks to see if you’re on a network admin screen (e.g. any admin page based on a /wp-admin/network/ URL). If so, the network_admin_notices hook fires.

Otherwise, is_user_admin() checks to see if you’re on a user admin screen (e.g. any admin page based on a /wp-admin/user/ URL). If so, the user_admin_notices hook fires. 

And, as you might have guessed, if both is_network_admin() and is_user_admin() return false then the admin_notices hook fires.

That just leaves the all_admin_notices hook. This hook isn’t part of the conditional expression discussed above, so this hook is guaranteed to display on all admin pages no matter what, including multisite network admin pages.

To clarify, for any WordPress admin page, only the all_admin_notices hook is guaranteed to always fire. Out of the other three hooks, only one will fire depending on the admin page you’re currently on.

I’d encourage you to take a look at admin-header.php (towards the end of the file) to see for yourself how WordPress evaluates when to use each admin notices hook.

We’ll only be using admin_notices throughout this tutorial series, but you may find you have a need for some of the other hooks in your own project, so it’s well worth checking them out.

Displaying Admin Notices on Specific Pages

Let’s turn our attention now to displaying admin notices on specific pages. First, comment out the call to add_action so our test notices aren’t displayed anymore.

Inside init(), add a new add_action() call that we’ll use to display an admin notice on one specific admin page.

Then define the specific_admin_page() method as follows:

Save your changes and view any page in the WordPress admin. I’ll try the main dashboard page.

Dashboard admin notice

As you can see, for any admin page you visit, the (base) name of the page is being displayed in the admin notice.

The get_current_screen() function returns a WP_Screen object with details about the current admin screen. The particular object property we’re interested in is WP_Screen->base, which evaluates to the base type of the current screen. Try loading different WordPress admin pages to see what values are returned for WP_Screen->base.

We can use the base value to conditionally load our admin notice only on the dashboard page. The value we need to check for is dashboard. Let’s also show an alternative admin notice if we aren’t on the admin dashboard page. Replace your definition of specific_admin_page() with:

Output base name of current admin page in the admin notice

Everything’s fine when we’re on the dashboard page, but try navigating to any other admin page and see what happens.

Error type admin notice shown when were not on the expected admin page

Using this simple approach gives us quite a bit of flexibility when displaying admin notices on specific admin pages. We can easily extend this to whitelist any number of admin pages we want to show admin notices on.

Once again, replace the specific_admin_pages() function, this time with the following code:

Instead of checking for a single admin page, we now check to see if the base name for the current admin page is in the $whitelist_admin_pages array. When we navigate to the dashboard, media library, or comments admin pages, we see our success admin notice.

Our success message shows on the admin comments page

And when we visit any other admin page (not included in our whitelist array), we see an alternate admin notice.

Only allowed admin pages show the success message

What about displaying an admin notice on a plugin options page? How would we go about that? Before we get into this, we first need to set up a dummy options page for our plugin.

Create a new file called plugin-options.php inside the admin-notices plugin folder we added earlier, and add the following code:

At the top of admin-notices.php (directly above the class declaration), include the plugin options class into the main plugin file with:

I’m not going into too much detail on how the code in plugin-options.php works as that could be a whole tutorial on its own! If you want a refresher then I’d recommend taking a look at the WordPress Codex page on adding plugin options pages.

Basically, all we’re doing is adding a new Admin Notices subpage to the Settings menu. The plugin options page itself contains a single text field which you can enter a string into. When the Save Changes button is clicked, the contents of the text field are saved to the WordPress database.

This is only a bare-bones example of a plugin settings page just for demonstration. It doesn’t include the necessary sanitization or translation functions recommended for a production plugin intended for general release.

Go to Settings > Admin Notices to view the plugin options page.

Plugin options page

As expected, the admin notice we added previously displays on our plugin options page. The error message is displayed because our plugin options page isn’t in the $whitelist_admin_pages array of allowed admin pages. Let’s fix that now.

In order to add our options page to the array, we need to know the base name. Inside specific_admin_page(), change the error admin notice div to the following:

We still get the same error admin notice as before, but this time it includes the base name we need, which turns out to be settings_page_admin-notices/plugin-options. That’s not a name we could have easily guessed, so it was worth taking the time to output it!

Add the base name to the $whitelist_admin_pages array, which should now look like this:

Refresh the plugin options page to see the updated admin notice.

Updated admin notice

Now that we know the plugin options page base name, we can easily create an admin notice that only displays on that admin page. Remove settings_page_admin-notices/plugin-options from the $whitelist_admin_pages array and comment out the second add_action function call in init(). Then add a third action we’ll use for our plugin options page only admin notice. Your init() function should now look like this:

Let’s flesh out the plugin_admin_notice() callback function now. Add this new method to the Gwyer_Admin_Notices class:

This is very similar to specific_admin_page() except we’ve removed the conditional expression. We also added a dismissible button by adding the is-dismissible CSS class, so the admin notice can now be closed too.

Plugin options page only admin notice

Try loading other admin pages to confirm that the admin notice only displays on the plugin options page.


In this tutorial, we learned more about admin notices and the various hooks available for displaying them. We also covered how to display admin notices only on specific pages of the WordPress admin. We developed a dedicated plugin to contain all the custom admin notice code.

In part three, we’ll further extend the plugin by showing how to trigger admin notices when certain events occur. Remember, the open-source nature of WordPress makes it easy to learn and extend. To that end, we have much to review and study in Envato Market if you’re curious.

We’ll then turn our attention to finding out how we can solve the persistent admin notice issue so that they don’t reappear when the page is refreshed. We’ll implement several different methods in our custom plugin to allow us to do this.

from Envato Tuts+ Code – WordPress