Last active
August 29, 2015 14:20
-
-
Save vajrasar/4fb87c492590588eb2d5 to your computer and use it in GitHub Desktop.
To show excerpt in tooltip while user hovers on title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .hide-excerpt { | |
| display: none; | |
| } | |
| #powerTip { | |
| max-width: 300px; | |
| white-space: normal !important; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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