Et pourquoi ne pas ajouter 1 scrollTo dans la #WP Admin Bar ?

Publié le

par

Crédits Photo Climbing Mount Feathertop by earthkath, on Flickr

Toute à l’heure j’ai découvert que lorsqu’on affichait le média joint (photo, vidéo..) à un tweet, la top barre de twitter se garnissait d’un nouveau bouton afin de masquer tous les médias ouverts.

Vous voyez mieux ce dont je parle ??

Ding : du coup j’ai eu une idée !

Et pourquoi ne pas utiliser la WP Admin Bar de WordPress pour inclure un bouton permettant de remonter en haut de la page (en un mot : ScrollTo). En effet sa position « fixed » nous assure de son affichage tout au long de notre descente de la page..

Et hop : côté Front si wp_admin_bar

Et puis l’avantage de mettre un scrollTo dans la WP Admin Bar, c’est qu’on peut aussi s’en servir depuis l’administration de notre blog…

Et hop : côté Back Office..

Dang : si le membre n’est pas loggé ou s’il a choisi de ne pas afficher cette top barre sur le front de son blog…

Tant que j’y étais, j’ai prévu ce cas en revenant au comportement initial du plugin jQuery développé par Matt.

Et hop : scroll to top classique..

Envie de tester ?

7 réponses à “Et pourquoi ne pas ajouter 1 scrollTo dans la #WP Admin Bar ?”

  1. Avatar de TheMyr34
    TheMyr34

    Sympa la dernière idée 2011 !

  2. Avatar de Vernon Fowler
    Vernon Fowler

    Hi there imath.
    I love this little UI enhancement. For some reason I can’t get it working on any BuddyPress component pages (such as activity, group, forum, or member directories). It works well on WordPress pages and the home page of the site.
    Any ideas to have it working everywhere?

  3. Avatar de Vernon Fowler
    Vernon Fowler

    Think I might have solved it for BuddyPress by changing

    add_action(‘template_redirect’, ‘imath_to_top_in_adminbar’, 1);

    to

    add_action(‘wp_head’, ‘imath_to_top_in_adminbar’, 1);

    My guess is that template_redirect isn’t always hookable in BuddyPress.

  4. Avatar de imath

    Hi Vernon,

    Thanks for your comment and trick to make it work in BuddyPress.. I haven’t tried it.. another option would have been to hook bp_actions ..
    😉

  5. Avatar de Vernon Fowler
    Vernon Fowler

    Hi Imath,

    Thanks again. I’m not sure if bp_actions would have worked for me as I don’t know whether that hook is available on standard WordPress pages. Our community site has both BuddyPress bits and WordPress pages so I went for the wp_head hook.

    The last modification I made is to strip the condition for checking the admin bar. I want a consistent user experience whether members are logged in or not. This cut down the code in functions.php by a few lines but more importantly provides a consistent UX.

    Now I am very happy.
    Thanks heaps for providing the original, well-written code (such that it can be easily modified to suit). 🙂 🙂

    1. Avatar de imath

      hi Vernon, you’re welcome 😉