Support » Plugin: Easy Notification Bar » Move Bar To Bottom

  • Resolved forau

    (@forau)


    Love the plugin but it would be extremely helpful if we had the option to have it at top or bottom of the page. 🙂

    Any quick solution to achieve this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author wpexplorer

    (@wpexplorer)

    Hi,

    This is AJ the theme author. By default the notification bar hooks into the new wp_body_open action hook to place it at the top of the page before any other content so we don’t have to use any advanced code to place it at the top via absolute position and then have the site content offset via javascript. This keeps things slim, fast and prevents issues with other 3rd party plugins that may insert content at the top of the site or theme sticky header functions.

    Having an option to change the placement would be a bit outside what I want to accomplish with the plugin as it will bloat things up.

    That said, if you want it at the bottom of the page in a fixed position it’s very easy with a little Custom CSS. Example:

    .easy-notification-bar {
    	position: fixed;
    	bottom: 0;
    	left: 0;
    	z-index: 999;
    }
    
    .easy-notification-bar--sticky {
    	top: auto;
    }

    I made a video showing how it will render with the added CSS: https://a.cl.ly/geugP6OE (adding the CSS under Appearance > Customize > Additional CSS). It’s a bit hard to see the changes with the video player’s bar at the bottom, so here is a screenshot as well: https://a.cl.ly/6qurJdbp

    Glad you like the plugin 😉

    – AJ

    Thread Starter forau

    (@forau)

    Apologies for the delay but that’s excellent, thankyou 🙂

    @wpexplorer If you exposed the Easy_Notification_Bar via a global var, someone could do something like this:

    global $easy_notification_bar; // Plugin author would have to make this available.
    if(has_action('wp_body_open', [$easy_notification_bar, 'display_notification'])) {
      remove_action('wp_body_open', [$easy_notification_bar, 'display_notification']);
      add_action('wp_footer', [$easy_notification_bar, 'display_notification'], 999);
    }

    And then the CSS to override is:

    .easy-notification-bar--sticky {
      bottom:0;
    }

    Support for that could probably be built in via a setting, too. Though it doesn’t handle AMP, which the plugin does.

    YMMV though, since not every theme is guaranteed to put their wp_footer() call just before </body>. Though how different is that gotcha than the “your theme may not do wp_body_open” gotcha.

    Plugin Author wpexplorer

    (@wpexplorer)

    @eclev91 – Good suggestions!

    But I think the best solution would be to add a new filter maybe something like “easy_notification_bar_hook” (I already have one named “easy_notification_bar_hook_priority” to change the default priority). This way you could easily change wp_body_open to any other hook you want. It would be much “cleaner” then removing the default action and then re-adding it.

    Not quite sure what you mean regarding your last comment but you are correct technically not every theme may put the ‘wp_body_open’ directly after the opening body tag or the ‘wp_footer’ hook before the closing body tag. But it’s pretty much the globally accepted standard. Most would agree that if these hooks aren’t added in such manner, the theme is incorrectly coded.

    – AJ

    ps: It’s technically possible to override any hook without setting the class to a global variable. I wrote this little function if you are curious to see how that could be done – https://gist.github.com/wpexplorer/53602f6139ed47e01d554af55feddd3f – That said, I will likely also change the Easy_Notification_Class to use static methods so you can easily access methods like display_notifcation if wanted via Easy_Notification_Class::display_notifcation() and convert the class into a singleton.

    @wpexplorer yes to all, and you got my last comment.

    Funny you mention that trick to track down a hook. I did something nearly identical myself in another situation.

    Saw the update and it’s much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Move Bar To Bottom’ is closed to new replies.