the_shortlink()
Displays the shortlink for a post.
Must be called from inside "The Loop"
Call like the_shortlink( __( 'Shortlinkage FTW' ) )
Uses: wp_get_shortlink()
1 time — 0.001029 sec (very slow) | 50000 times — 4.65 sec (fast) | PHP 7.1.2, WP 4.7.3
Hooks from the function
Return
null
. Nothing (null).
Usage
the_shortlink( $text, $title, $before, $after );
- $text(string)
- Optional The link text or HTML to be displayed.
Default: 'This is the short link.' - $title(string)
- Optional The tooltip for the link. Must be sanitized.
Default: sanitized post title - $before(string)
- Optional HTML to display before the link.
Default: '' - $after(string)
- Optional HTML to display after the link.
Default: ''
Examples
#1 Display a short link with the text "This is the short link":
<?php the_shortlink(); ?>
We get it:
<a rel="shortlink" href="http://example.com/?p=1234" title="post title">This is the shortlink</a>
#2 Display the link inside the html tags
Tags will only appear when a short link is displayed:
<?php the_shortlink( 'shortlink', null, '<div class="shortlink">', '</div>'); ?
We get it:
<div class='shortlink'><a rel="shortlink" href="http://example.com/?p=1234" title="title posts">shortlink</a></div>
Changelog
Since 3.0.0 | Introduced. |