Example 1 — Default short link
Print the link with the default text.
<?php the_shortlink(); ?> How It Works
the_shortlink()builds an anchor tag.- The
hrefis the short URL of the post. - The
titleis the post title.

In WordPress, the_shortlink() prints a link to the short URL of the post, such as https://example.com/?p=12. Short links are easy to share.
It prints a full anchor tag. If you only need the URL, use wp_get_shortlink().
A few ways to call the_shortlink().
<?php
the_shortlink( 'Short link' ); | Call | What it does |
|---|---|
the_shortlink() | Print a link with the default text. |
the_shortlink( 'Short link' ) | Use your own link text. |
the_shortlink( 'Short link', 'Copy this', '<p>', '</p>' ) | Add a title and wrapping tags. |
wp_get_shortlink() | Return only the URL. |
It prints the link. The default text is This is the short link.
the_shortlink( string $text = '', string $title = '', string $before = '', string $after = '' ): void | Parameter | Description |
|---|---|
$text | string. The link text. Default is This is the short link. |
$title | string. The title attribute. Default is the post title. |
$before | string. Text or HTML before the link. Default is empty. |
$after | string. Text or HTML after the link. Default is empty. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The link is printed. |
Three short examples. Each one shows the code and what it prints.
Print the link with the default text.
<?php the_shortlink(); ?> the_shortlink() builds an anchor tag.href is the short URL of the post.title is the post title.Change the text of the link.
<?php the_shortlink( 'Share this short link' ); ?> title falls back to the post title.Use the last two arguments to add tags.
<?php the_shortlink( 'Short link', '', '<p class="short">', '</p>' ); ?> Open the functions index for simple guides with examples and FAQs.
10 people found this page helpful