Tooltips in single post


Hey, I'd like to share this, it may please someone:

beans_add_attribute( 'beans_previous_link[_post_navigation]', 'data-uk-tooltip', '{pos:\'top\', animation:true, delay:\'200\'}' );

beans_add_attribute( 'beans_next_link[_post_navigation]', 'data-uk-tooltip', '{pos:\'top\', animation:true, delay:\'200\'}' );

those both go to function.php. This one below to single.php inside a function:

beans_uikit_enqueue_components( array( 'tooltip' ), 'add-ons' );

And mostly if it's doom don't let me this way. Thank you.


Hey Oliver,

Thanks for sharing πŸ™‚ You may actually put everything is single.php if it is what you are targeting. Don't forget to wrap beans_uikit_enqueue_components() in an beans_uikit_enqueue_scripts action which is good practice. Your complete single.php file would look like that.

<?php

// Enqueue UIkit components.
add_action( 'beans_uikit_enqueue_scripts', 'example_view_enqueue_uikit_assets' );

function example_view_enqueue_uikit_assets() {
  beans_uikit_enqueue_components( array( 'tooltip' ), 'add-ons' );
}

// Add tooltip attributes.
beans_add_attribute( 'beans_previous_link[_post_navigation]', 'data-uk-tooltip', "{pos:'top', animation:true, delay:200}" );
beans_add_attribute( 'beans_next_link[_post_navigation]', 'data-uk-tooltip', "{pos:'top', animation:true, delay:200}" );

// Load the document which is always needed at the bottom of template files.
beans_load_document();

Happy coding πŸ™‚


Ok, thank you, in fact I missed the correct practice, I had:

beans_add_smart_action( 'beans_before_load_document', 'dequeue_enqueue_components' );
function dequeue_enqueue_components() {
// DEQUEUE UIKIT COMPONENTS.
  beans_uikit_dequeue_components( array( 'modal', 'cover' ), 'core' );
  // ADD THE THEME STYLE AS A UIKIT FRAGMENT TO HAVE ACCESS TO ALL THE VARIABLES.
  // ADD THE THEME JS AS A UIKIT FRAGMENT.
  // INCLUDE UIKIT COMPONENTS NEEDED.
  // beans_uikit_enqueue_components( array( 'cover', 'flex', 'grid' ) );
  beans_uikit_enqueue_components( array( 'tooltip' ), 'add-ons' );
}

So it was not a good behave, now I changed: beans_before_load_document with: beans_uikit_enqueue_scripts.

By the way to be DRY, may I centralize this "dequeue components" in a single php page called by a:

require_once( get_stylesheet_directory() . '/lib/assets/helpers/dequeue.php' );

just beside my translate.php and cleaner.php from JCM ; )

I means does it matter that I dequeue for example grid and enqueue it at once after ? For my skills not, I think it's in cache so it's doesn't matter, but in real how is it, do I consume one request in server for nothing or worse ?


Hey Oliver,

No it doesn't really matter if you dequeue and enqueue components multiple times from different points in your application, Beans does the job of only keeping relevent enqueues for you. In fact even if you add to enqueue the same script 10 times, it would only load it once indeed πŸ™‚

Have fun,


Write a reply

Login or register to write a reply, it's free!