Add tooltips
-
Hi,
This a simple proposal for your plugin. I added a shortcode to look into the database to display the description of an entry in the page using the glossary. I think it is a very useful feature. Here the code snippet used.I have integrated as an helper in the code for the next version of my (very) new plugin (Slithy Web) if your plugin is active but it is a hack…
Here the code I used to achieve it (the page reference shows the running code for “SEO”), feel free to reuse:
public function tooltip_shortcode($atts, $contents = null, $tag=''){ extract(shortcode_atts(array( 'name' => null, 'text' => null, 'dir' => null), $atts)); wp_enqueue_style('slithy_css'); if( $name ){ global $wpdb; // We rely on the "Name Directory" plugin if exists $directory = intval($dir); $query = "SELECT description FROM {$wpdb->prefix}name_directory_name WHERE name = %s"; if($directory > 0){ $query .= " AND directory = $directory"; } $final_query = $wpdb->prepare($query, $name); $definition = $wpdb->get_var($final_query); if($definition){ $text = $definition; if(!$contents){ // If we have found something and no contents provided, // use the name as the text. $contents = $name; } } } return '<span class="tooltip">' . esc_attr($contents) . '<span class="tooltiptext">' . esc_attr($text) . '</span></span>'; }
The CSS code has been taken from https://www.w3schools.com/css/tryit.asp?filename=trycss_tooltip
Feel free to contact me for further details and congratulations for your work.
The page I need help with: [log in to see the link]
- The topic ‘Add tooltips’ is closed to new replies.