WordPress the_shortlink() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a short link

Definition

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().

Syntax

A few ways to call the_shortlink().

WordPress
<?php
the_shortlink( 'Short link' );
CallWhat 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.

Full declaration
WordPress
the_shortlink( string $text = '', string $title = '', string $before = '', string $after = '' ): void

Parameters

ParameterDescription
$textstring. The link text. Default is This is the short link.
$titlestring. The title attribute. Default is the post title.
$beforestring. Text or HTML before the link. Default is empty.
$afterstring. Text or HTML after the link. Default is empty.

Return Value

Return ValueDescription
voidNothing is returned. The link is printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Default short link

Print the link with the default text.

WordPress
<?php the_shortlink(); ?>

How It Works

  1. the_shortlink() builds an anchor tag.
  2. The href is the short URL of the post.
  3. The title is the post title.

Example 2 — Use your own text

Change the text of the link.

WordPress
<?php the_shortlink( 'Share this short link' ); ?>

How It Works

  1. The first argument is the link text.
  2. The URL stays the same.
  3. The title falls back to the post title.

Example 3 — Wrap it in a paragraph

Use the last two arguments to add tags.

WordPress
<?php the_shortlink( 'Short link', '', '<p class="short">', '</p>' ); ?>

How It Works

  1. The third argument goes before the link.
  2. The fourth goes after the link.
  3. The wrapper is printed only when a link exists.

Frequently Asked Questions

It prints a link to the short URL of the current post.
By default it looks like https://example.com/?p=12, where 12 is the post ID.
Use wp_get_shortlink().
Pass your text as the first argument.
Yes. It uses the current post.

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful