WordPress at a glance

the_shortlink() WP 1.0

Displays the shortlink for a post.

Must be called from inside "The Loop"

Call like the_shortlink( __( 'Shortlinkage FTW' ) )

Works based on: wp_get_shortlink()
✈ 1 time = 0.001029s = very slow | 50000 times = 4.65s = fast PHP 7.1.2, WP 4.7.3

No Hooks.

Return

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: ''

Code of the_shortlink: wp-includes/link-template.php VER 5.0.1

<?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;
	}
}

Related Functions

From tag: Link (tag A in HTML)

More from category: Other

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register