the_shortlink( string $text = '', string $title = '', string $before = '', string $after = '' )
Displays the shortlink for a post.
Description Description
Must be called from inside "The Loop"
Call like the_shortlink( __( ‘Shortlinkage FTW’ ) )
Parameters Parameters
- $text
-
(string) (Optional) The link text or HTML to be displayed. Defaults to 'This is the short link.'
Default value: ''
- $title
-
(string) (Optional) The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
Default value: ''
- $before
-
(string) (Optional) HTML to display before the link.
Default value: ''
- $after
-
(string) (Optional) HTML to display after the link.
Default value: ''
Source Source
File: wp-includes/link-template.php
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { $post = get_post(); if ( empty( $text ) ) { $text = __( 'This is the short link.' ); } if ( empty( $title ) ) { $title = the_title_attribute( array( 'echo' => false ) ); } $shortlink = wp_get_shortlink( $post->ID ); if ( ! empty( $shortlink ) ) { $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $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. */ $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); echo $before, $link, $after; } }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Custom Text
Displays link with the specified text.
Output:
Shortlinkage FTW
Default Usage
Displays link with “This is the short link.” as the text.
Output:
This is the short link.
Conditional HTML
Displays link with prefix and suffix HTML that will appear only when the shortlink URL is available.