Title: wp_admin_bar_shortlink_menu
Published: April 25, 2014
Last modified: May 20, 2026

---

# wp_admin_bar_shortlink_menu( WP_Admin_Bar $wp_admin_bar )

## In this article

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

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

Provides a shortlink.

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

 `$wp_admin_bar`[WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
required

The [WP_Admin_Bar](https://developer.wordpress.org/reference/classes/wp_admin_bar/)
instance.

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

    ```php
    function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
    	$short = wp_get_shortlink( 0, 'query' );
    	$id    = 'get-shortlink';

    	if ( empty( $short ) ) {
    		return;
    	}

    	$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" aria-label="' . __( 'Shortlink' ) . '" />';

    	$wp_admin_bar->add_node(
    		array(
    			'id'    => $id,
    			'title' => __( 'Shortlink' ),
    			'href'  => $short,
    			'meta'  => array( 'html' => $html ),
    		)
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/admin-bar.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/admin-bar.php#L773)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/admin-bar.php#L773-L791)

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

| Uses | Description | 
| [wp_get_shortlink()](https://developer.wordpress.org/reference/functions/wp_get_shortlink/)`wp-includes/link-template.php` |

Returns a shortlink for a post, page, attachment, or site.

  | 
| [WP_Admin_Bar::add_node()](https://developer.wordpress.org/reference/classes/wp_admin_bar/add_node/)`wp-includes/class-wp-admin-bar.php` |

Adds a node to the menu.

  | 
| [__()](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.

  |

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

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

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.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_admin_bar_shortlink_menu%2F)
before being able to contribute a note or feedback.