Title: wp_get_tooltip_helper
Published: August 20, 2026

---

# wp_get_tooltip_helper( string $content, array $args = array() ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#wp--skip-link--target)

Retrieves the markup for an accessible tooltip or toggletip.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#description)󠁿

Returns a button and either a hover/focus triggered tooltip popover or an action
triggered toggle tip. Enqueue the `wp-tooltip` style and script where it is used.

Tooltips are used to show the accessible name of a control.Toggletips are used for
longer supporting text explaining context.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#parameters)󠁿

 `$content`stringrequired

Plain-text tooltip content. An empty value returns an empty string.

`$args`arrayoptional

Arguments for building the tooltip.

 * `id` string
 * Unique ID for the popover element. Default is a generated unique ID.
 * `button` string
 * Existing `button` or `a` markup. Used instead of generated button.
    Default standard
   button HTML.
 * `label` string
 * Accessible label for the toggle button.
    Default `'Help'`, matching the default
   icon. Ignored for tooltips.
 * `close_label` string
 * Accessible label for the close button. Default `'Close'`.
 * `icon` string
 * Dashicons icon class for the toggle button.
    Default `'dashicons-editor-help'`.
   Should match the control’s visible label.
 * `class` string
 * Additional class(es) for the wrapping element.
 * `type` string
 * Type of tooltip: either `tooltip` or `toggletip`.
    Default `'tooltip'`.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#return)󠁿

 string Tooltip HTML markup, or an empty string when no content is provided.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#source)󠁿

    ```php
    function wp_get_tooltip_helper( $content, $args = array() ) {
    	$content = trim( (string) $content );

    	if ( '' === $content ) {
    		return '';
    	}

    	$defaults = array(
    		'id'          => wp_unique_id( 'wp-tooltip-' ),
    		'button'      => '<button type="button" aria-label="%3$s"><span class="dashicons %4$s" aria-hidden="true"></span></button>',
    		'label'       => __( 'Help' ),
    		'close_label' => __( 'Close' ),
    		'icon'        => 'dashicons-editor-help',
    		'class'       => '',
    		'type'        => 'tooltip',
    	);

    	$args = wp_parse_args( $args, $defaults );

    	$classes = ( 'tooltip' === $args['type'] ) ? 'wp-tooltip wp-is-tooltip' : 'wp-tooltip wp-is-toggletip';
    	if ( '' !== $args['class'] ) {
    		$classes .= ' ' . $args['class'];
    	}

    	$icon      = ( $args['icon'] ) ? trim( $args['icon'] ) : $defaults['icon'];
    	$id        = ( $args['id'] ) ? $args['id'] : $defaults['id'];
    	$button    = ( $args['button'] ) ? $args['button'] : $defaults['button'];
    	$processed = false;
    	$processor = new WP_HTML_Tag_Processor( $button );
    	if ( true === $processor->next_tag( 'button' ) ) {
    		$processor->add_class( 'wp-tooltip__toggle' );
    		if ( 'tooltip' !== $args['type'] ) {
    			$processor->set_attribute( 'popovertarget', '%2$s' );
    			$processor->set_attribute( 'aria-haspopup', 'dialog' );
    		}
    		$button    = $processor->get_updated_html();
    		$processed = true;
    	} else {
    		// Reset processor.
    		$processor = new WP_HTML_Tag_Processor( $button );
    		if ( true === $processor->next_tag( 'a' ) && 'tooltip' === $args['type'] ) {
    			$processor->add_class( 'wp-tooltip__toggle' );
    			$button    = $processor->get_updated_html();
    			$processed = true;
    		}
    	}
    	if ( ! $processed ) {
    		// Button HTML passed was not valid.
    		$processor = new WP_HTML_Tag_Processor( $defaults['button'] );
    		$processor->add_class( 'wp-tooltip__toggle' );
    		if ( 'tooltip' !== $args['type'] ) {
    			$processor->set_attribute( 'popovertarget', '%2$s' );
    			$processor->set_attribute( 'aria-haspopup', 'dialog' );
    		}
    		$button = $processor->get_updated_html();
    	}

    	/*
    	 * The markup only uses phrasing content so it is valid when nested
    	 * in a phrasing context. Sectioning content (e.g. `div`, `dialog`) will
    	 * cause the parser to close an open `p`, creating an empty and breaking
    	 * the layout. See #65660.
    	 */
    	if ( 'tooltip' === $args['type'] ) {
    		// Tooltips are only used to visually display labels.
    		$label  = wp_strip_all_tags( $content, true );
    		$markup = sprintf(
    			'<span class="%1$s">
    				' . $button . '
    				<span popover="hint" id="%2$s" class="wp-tooltip__bubble" role="tooltip">' .
    					'<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
    				'</span>' .
    			'</span>',
    			esc_attr( $classes ),
    			esc_attr( $id ),
    			esc_attr( $label ),
    			esc_attr( $icon ),
    			esc_html( $content ),
    		);
    	} else {
    		/*
    		 * A `span` with `role="dialog"` is used instead of a `dialog` element to keep the
    		 * markup as phrasing content. The `aria-label`, `tabindex`, and `autofocus`
    		 * attributes reproduce the accessible name and focus handling of the native element.
    		 */
    		$markup = sprintf(
    			'<span class="%1$s">
    				' . $button . '
    				<span popover="auto" id="%2$s" class="wp-tooltip__bubble" role="dialog" aria-label="%3$s" tabindex="-1" autofocus>' .
    					'<span id="%2$s-text" class="wp-tooltip__text">%5$s</span>' .
    					'<button type="button" class="wp-tooltip__close" popovertarget="%2$s" popovertargetaction="hide" aria-label="%6$s">' .
    						'<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>' .
    					'</button>' .
    				'</span>' .
    			'</span>',
    			esc_attr( $classes ),
    			esc_attr( $id ),
    			esc_attr( $args['label'] ),
    			esc_attr( $icon ),
    			esc_html( $content ),
    			esc_attr( $args['close_label'] ),
    		);
    	}

    	return $markup;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L467)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L467-L572)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_HTML_Tag_Processor::__construct()](https://developer.wordpress.org/reference/classes/wp_html_tag_processor/__construct/)`wp-includes/html-api/class-wp-html-tag-processor.php` |

Constructor.

  | 
| [wp_unique_id()](https://developer.wordpress.org/reference/functions/wp_unique_id/)`wp-includes/functions.php` |

Gets unique ID.

  | 
| [wp_strip_all_tags()](https://developer.wordpress.org/reference/functions/wp_strip_all_tags/)`wp-includes/formatting.php` |

Properly strips all HTML tags including ‘script’ and ‘style’.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#)

| Used by | Description | 
| [wp_get_tooltip()](https://developer.wordpress.org/reference/functions/wp_get_tooltip/)`wp-includes/general-template.php` |

Retrieves the markup for an accessible tooltip.

  | 
| [wp_get_toggletip()](https://developer.wordpress.org/reference/functions/wp_get_toggletip/)`wp-includes/general-template.php` |

Retrieves the markup for an accessible toggle tip.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_tooltip_helper/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_tooltip_helper%2F)
before being able to contribute a note or feedback.