WordPress.org

Make WordPress Core

Ticket #10640: 10640.4.diff

File 10640.4.diff, 1.7 KB (added by miqrogroove, 8 years ago)

Whipped this up during the IRC meeting. Patch is not tested.

  • wp-includes/link-template.php

     
    20812081        $shortlink = '';
    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 )
    20872087                        $shortlink = home_url('?p=' . $post->ID);
     
    21052105        if ( empty($shortlink) )
    21062106                return;
    21072107
    2108         echo '<link rel="shortlink" href="' . $shortlink . '" />';
     2108        echo "<link rel='shortlink' href='" . $shortlink . "' />\n";
    21092109}
    21102110
    21112111/**
     
    21292129        header('Link: <' . $shortlink . '>; rel=shortlink', false);
    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?>