WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/the shortlink

Description

Used on single post permalink 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() if you want to return the permalink to a post for use in PHP.

This tag can not be used outside of The Loop.

Note: This function outputs the complete shortlink for the post, to return the shortlink use wp_get_shortlink().

Usage

 <?php the_shortlink$text$title$before$after ); ?> 

Parameters

$text
(string) (optional) Link text to display.
Default: 'This is the short link.'
$title
(string) (optional) Tool-tip text displayed with the link.
Default: post title
$before
(string) (optional) Text or HTML prefix added to the link.
Default: None
$after
(string) (optional) Text or HTML suffix added to the link.
Default: None

Examples

Default Usage

Displays link with "This is the short link." as the text.

This is the short link.

 <?php the_shortlink(); ?> 

Custom Text

Displays link with the specified text.

Shortlinkage FTW

 <?php the_shortlink(__('Shortlinkage FTW')); ?> 

Conditional HTML

Displays link with prefix and suffix HTML that will appear only when the shortlink URL is available.

 <?php the_shortlink('short link'null'<ul><li>''</li></ul>'); ?> 

Source File

the_shortlink() is located in wp-includes/link-template.php.

Change Log

  • Since: 3.0.0

Related

See also index of Function Reference and index of Template Tags.