WordPress.org

Make WordPress Core

Changeset 13683


Ignore:
Timestamp:
03/12/2010 04:08:37 PM (10 years ago)
Author:
ryan
Message:

the_shortlink(). Props miqrogroove. fixes #10640

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r13650 r13683  
    20822082
    20832083    // Return p= link for posts.
    2084     if ( !empty($post_id) ) {
     2084    if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
    20852085        $post = get_post($post_id);
    20862086        if ( isset($post->post_type) && 'post' == $post->post_type )
     
    21062106        return;
    21072107
    2108     echo '<link rel="shortlink" href="' . $shortlink . '" />';
     2108    echo "<link rel='shortlink' href='" . $shortlink . "' />\n";
    21092109}
    21102110
     
    21302130}
    21312131
     2132/**
     2133 * Display the Short Link for a Post
     2134 *
     2135 * Must be called from inside "The Loop"
     2136 *
     2137 * Call like the_shortlink(__('Shortlinkage FTW'))
     2138 *
     2139 * @since 3.0.0
     2140 *
     2141 * @param string $text Optional The link text or HTML to be displayed.  Defaults to 'This is the short link.'
     2142 * @param string $title Optional The tooltip for the link.  Must be sanitized.  Defaults to the sanitized post title.
     2143 * @param string $before Optional HTML to display before the link.
     2144 * @param string $before Optional HTML to display after the link.
     2145 */
     2146function the_shortlink($text = '', $title = '', $before = '', $after = '') {
     2147    global $post;
     2148
     2149    if ( empty($text) )
     2150        $text = __('This is the short link.');
     2151
     2152    if ( empty($title) )
     2153        $title = the_title_attribute( array('echo' => FALSE) );
     2154
     2155    $shortlink = wp_get_shortlink($post->ID);
     2156
     2157    if ( !empty($shortlink) )
     2158        echo "$before<a rel='shortlink' href='$shortlink' title='$title'>$text</a>$after";
     2159}
     2160
    21322161?>
Note: See TracChangeset for help on using the changeset viewer.