• Home
  • blog
  • Introducing the SitePoint Random Hello Bar WordPress Plugin

Introducing the SitePoint Random Hello Bar WordPress Plugin

Category: Plugins, Web, Wordpress

If you’re a regular SitePoint reader, you may have noticed a small feature we refer to as the Hello Bar. If you scroll far enough down this page you should see it slide in from the top of the screen. It should look something like this:

An image showing an example of what the SitePoint random Hello Bar looks like when deployed

We feel it’s an unobtrusive way of adding advertising, product announcements or other messages to a page, so we thought it was time to share it with you. In this article I’m going take you through how we put it together and then show some examples of how you can truly make it your own. If you prefer to just skip to the code, it’s available on GitHub, npm or the WordPress Plugin Directory.

WordPress Admin Interface

The entry point to our plugin is sp-random-hello-bar.php and the plugin’s main class at src/SitePoint/RandomHelloBar.php.


require_once(plugin_dir_path( __FILE__ ).'src/SitePoint/RandomHelloBar.php');


if (is_admin()) {


namespace SitePoint;

class RandomHelloBar {
  const PLUGIN_NAME = 'sp-random-hello-bar';

  private static function get_option($option) {
    return get_option(self::PLUGIN_NAME.'-'.$option);

  private static function update_option($option, $value) {
    return update_option(self::PLUGIN_NAME.'-'.$option, $value);

  private static function delete_option($option) {
    return delete_option(self::PLUGIN_NAME.'-'.$option);


To create our admin UI we’re going take advantage of the WordPress Settings API as it allows admin pages containing settings forms to be managed semi-automatically. We add a SP Random Hello Bar sub-menu under the Settings menu via the add_options_page function. Then we register sp-random-hello-bar-enabled and sp-random-hello-bar-ads settings and the sections they belong to.

Continue reading %Introducing the SitePoint Random Hello Bar WordPress Plugin%