Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save vajrasar/4fb87c492590588eb2d5 to your computer and use it in GitHub Desktop.

Select an option

Save vajrasar/4fb87c492590588eb2d5 to your computer and use it in GitHub Desktop.
To show excerpt in tooltip while user hovers on title
.hide-excerpt {
display: none;
}
#powerTip {
max-width: 300px;
white-space: normal !important;
}
<?php
//* Enqueue PowerTip
add_action( 'wp_enqueue_scripts', 'sk_load_powertip' );
function sk_load_powertip() {
// Won't enqueue if the device is mobile as there is no hover functionality for those devices
if ( wp_is_mobile() ) {
return;
}
if( is_home() ) {
wp_enqueue_style( 'powertip-css', get_stylesheet_directory_uri() . '/css/jquery.powertip.min.css' );
wp_enqueue_script( 'powertip', get_stylesheet_directory_uri() . '/js/jquery.powertip.min.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'powertip-init', get_stylesheet_directory_uri() .'/js/powertip-init.js' , array( 'powertip' ), '1.0.0', true );
}
}
add_action( 'genesis_entry_content', 'vg_show_hide_excerpt', 10 );
function vg_show_hide_excerpt() {
if( is_home() ) {
?>
<div class="hide-excerpt">
<?php the_excerpt(); ?>
</div>
<?php
}
}
jQuery(document).ready(function($) {
// Find each .hide-excerpts to get its contents
$( '.hide-excerpt' ).each(function() {
var excerpt = $(this).text(),
// Find it's parent .entry
$postContainer = $(this).closest( '.entry' );
//* Now from the parent, find the .entry-title and change title to excerpt
$postContainer.find( '.entry-title' ).attr( 'title', excerpt );
});
$('.entry-title').powerTip({
followMouse: 'true'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment