Title: Expanding shortcode capabilities
Last modified: May 4, 2019

---

# Expanding shortcode capabilities

 *  [screamson](https://wordpress.org/support/users/screamson/)
 * (@screamson)
 * [7 years ago](https://wordpress.org/support/topic/expanding-shortcode-capabilities/)
 * Hi!
    I slightly modified your excellent plugin for the needs. And I thought: 
   maybe it’s like the author and she will add it? To Display a previously created
   tooltip, you use a shortcode: `[act_tooltip id="XX"/]` Where id – is id of tooltip.
   But suppose that we have a website recipes. Each recipe has a list of products.
   It is selected by the editor when editing a recipe. We want to show the user 
   a tooltip for each ingredient. In order not to overload the tooltips on the page,
   we use the shortcode specified above. But to register compliance for each ingredient
   the ID of the tooltip is ineffective. So I did the following: Changed the value
   of the “title” parameter in the function to replace the ID. In file `advanced-
   custom-tooltips/public/class-advanced-custom-tooltips-public.php` I changed the“
   tooltip_shortcode” function:
 *     ```
       	/**
       	 * Tooltip shortcode.
       	 *
       	 * @since    1.0.0
       	 */
       	 public function tooltip_shortcode( $atts, $code_content ) {
   
       		 if( !isset( $atts['title'] ) && !isset( $atts['content'] ) && !isset( $atts['id'] ) ) { //No tooltip ID or content provided, do nothing
       		 	return;
       		 }
       		 if( isset( $atts['title'] ) && isset( $atts['id'] ) ) { //Both ID and Title tooltip, do nothing
       		 	return;
       		 }
   
       		 $defaults = extract( shortcode_atts(array(
       			 'id' => '',
       			 'title' => '',
       			 'content' => '',
       		 ), $atts, 'act-tooltip-shortcode-atts' ) );
   
       		 if( !isset( $atts['id'] ) && isset( $atts['title'] ) ) { //Plain text tooltip
   
       			query_posts( 'post_type=act_tooltip&title=' . $title );
   
       		 	if ( have_posts()) : while (have_posts()) : the_post();
   
       			 if( $code_content ) {
       				 $tooltip_text = $code_content;
       			 } else {
       				 $tooltip_text = get_the_title();
       			 }
   
       			 $tooltip_content = $this->format_tooltip_content( get_the_content() );
   
       		 endwhile; endif; wp_reset_query();
   
       		 return '<span class="act-tooltip" title="' . $tooltip_content . '">' . $tooltip_text . '</span>';				 
       		 }
       		 if( isset( $atts['id'] ) && !isset( $atts['title'] ) ) {
       		 //ID provided, get this tooltip from db
       		 query_posts( 'post_type=act_tooltip&p=' . $id );
   
       		 if ( have_posts()) : while (have_posts()) : the_post();
   
       			 if( $code_content ) {
       				 $tooltip_text = $code_content;
       			 } else {
       				 $tooltip_text = get_the_title();
       			 }
   
       			 $tooltip_content = $this->format_tooltip_content( get_the_content() );
   
       		 endwhile; endif; wp_reset_query();
   
       		 return '<span class="act-tooltip" title="' . $tooltip_content . '">' . $tooltip_text . '</span>';			 
   
       		 }
   
       	 }
       ```
   
 * Now in the recipe page template code I write the following
    `echo do_shortcode('[
   act_tooltip title="'.$ingredient.'" /]');` Where $ingredient is the name of the
   ingredient. But here the name of the tooltip must be identical to the name of
   the ingredient. For me it is very much reduced the time to fill the site. I hope
   I can help someone. P.S.: I am from Russia and write through a translator. I 
   apologize for the mistakes in the text.

The topic ‘Expanding shortcode capabilities’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/advanced-custom-tooltips_bc133e.svg)
 * [Advanced Custom Tooltips](https://wordpress.org/plugins/advanced-custom-tooltips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-custom-tooltips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-custom-tooltips/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-custom-tooltips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-custom-tooltips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-custom-tooltips/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [screamson](https://wordpress.org/support/users/screamson/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/expanding-shortcode-capabilities/)
 * Status: not a support question