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

---

# the_shortlink( string $text = '', string $title = '', string $before = '', string $after = '' )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#user-contributed-notes)

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

Displays the shortlink for a post.

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

Must be called from inside “The Loop”

Call like the_shortlink( __( ‘Shortlinkage FTW’ ) )

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

 `$text`stringoptional

The link text or HTML to be displayed. Defaults to ‘This is the short link.’

Default:`''`

`$title`stringoptional

Unused.

Default:`''`

`$before`stringoptional

HTML to display before the link.

Default:`''`

`$after`stringoptional

HTML to display after the link.

Default:`''`

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#more-information)󠁿

Used on single post [permalink](https://wordpress.org/support/article/glossary/)
pages, this template tag displays a “URL shortening” link for the current post. 
By default, this will mean the URL has a format of /?p=1234, and will only appear
if pretty permalinks are enabled.

However, this feature is limited by design and intended to be leveraged by plugins
that may offer links in a different format, a custom format, or even a format provided
by a third-party URL shortening service. Refer to [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)
if you want to return the permalink to a post for use in PHP.

**Note**: This function outputs the complete shortlink for the post, to return the
shortlink use [wp_get_shortlink()](https://developer.wordpress.org/reference/functions/wp_get_shortlink/).

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

    ```php
    function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
    	$post = get_post();

    	if ( empty( $text ) ) {
    		$text = __( 'This is the short link.' );
    	}

    	$shortlink = wp_get_shortlink( $post->ID );

    	if ( ! empty( $shortlink ) ) {
    		$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '">' . $text . '</a>';

    		/**
    		 * Filters the short link anchor tag for a post.
    		 *
    		 * @since 3.0.0
    		 *
    		 * @param string $link      Shortlink anchor tag.
    		 * @param string $shortlink Shortlink URL.
    		 * @param string $text      Shortlink's text.
    		 * @param string $title     Shortlink's title attribute. Unused.
    		 */
    		$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title );
    		echo $before, $link, $after;
    	}
    }
    ```

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

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#hooks)󠁿

 [apply_filters( ‘the_shortlink’, string $link, string $shortlink, string $text, string $title )](https://developer.wordpress.org/reference/hooks/the_shortlink/)

Filters the short link anchor tag for a post.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/the_shortlink/?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.

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

Retrieves the translation of $text.

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

Checks and cleans a URL.

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

Calls the callback functions that have been added to a filter hook.

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

Retrieves post data given a post ID or post object.

  |

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

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

| Version | Description | 
| [6.8.0](https://developer.wordpress.org/reference/since/6.8.0/) | Removed title attribute. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#comment-content-795)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_shortlink/#comment-795)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-795)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-795)
 4.  **Custom Text**
      Displays link with the specified text.
 5.      ```php
         <?php the_shortlink( __( 'Shortlinkage FTW', 'textdomain' ) ); ?> 
         ```
     
 6.  Output:
      [Shortlinkage FTW](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%3Freplytocom%3D795%23feedback-editor-795)
 8.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#comment-content-794)
 9.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_shortlink/#comment-794)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-794)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-794)
 11. **Default Usage**
      Displays link with “This is the short link.” as the text.
 12.     ```php
          <?php the_shortlink(); ?> 
         ```
     
 13. Output:
 14. [This is the short link.](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#)
 15.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%3Freplytocom%3D794%23feedback-editor-794)
 16.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/the_shortlink/?output_format=md#comment-content-796)
 17.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/the_shortlink/#comment-796)
 18. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-796)
     Vote results for this note: -1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%23comment-796)
 19. **Conditional HTML**
      Displays link with prefix and suffix HTML that will appear
     only when the shortlink URL is available.
 20.     ```php
         <?php the_shortlink( 'short link', null, '<ul><li>', '</li></ul>' ); ?> 
     
         <a href="#" rel="nofollow">short link</a>
         ```
     
 21.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fthe_shortlink%2F%3Freplytocom%3D796%23feedback-editor-796)

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