the_shortlink

The timeline below displays how wordpress function the_shortlink has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 4.6

/**
 * Displays the shortlink for a post.
 *
 * Must be called from inside "The Loop"
 *
 * Call like the_shortlink( __( 'Shortlinkage FTW' ) )
 *
 * @since 3.0.0
 *
 * @param string $text   Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
 * @param string $title  Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link. Default empty.
 * @param string $after  Optional HTML to display after the link. Default empty.
 */
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;
    }
}

WordPress Version: 4.3

/**
 * Display the Short Link for a Post
 *
 * Must be called from inside "The Loop"
 *
 * Call like the_shortlink(__('Shortlinkage FTW'))
 *
 * @since 3.0.0
 *
 * @param string $text   Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
 * @param string $title  Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link.
 * @param string $after  Optional HTML to display after the link.
 */
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>';
        /**
         * Filter the shortlink 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;
    }
}

WordPress Version: 3.9

/**
 * Display the Short Link for a Post
 *
 * Must be called from inside "The Loop"
 *
 * Call like the_shortlink(__('Shortlinkage FTW'))
 *
 * @since 3.0.0
 *
 * @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
 * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link.
 * @param string $after Optional HTML to display after the link.
 */
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>';
        /**
         * Filter the shortlink 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;
    }
}

WordPress Version: 3.7

/**
 * Display the Short Link for a Post
 *
 * Must be called from inside "The Loop"
 *
 * Call like the_shortlink(__('Shortlinkage FTW'))
 *
 * @since 3.0.0
 *
 * @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
 * @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link.
 * @param string $after Optional HTML to display after the link.
 */
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>';
        $link = apply_filters('the_shortlink', $link, $shortlink, $text, $title);
        echo $before, $link, $after;
    }
}