the_shortlink(). Props miqrogroove. fixes #10640
git-svn-id: http://svn.automattic.com/wordpress/trunk@13683 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aa92bfad14
commit
97e3559079
|
@ -2081,7 +2081,7 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {
|
||||||
$shortlink = '';
|
$shortlink = '';
|
||||||
|
|
||||||
// Return p= link for posts.
|
// Return p= link for posts.
|
||||||
if ( !empty($post_id) ) {
|
if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if ( isset($post->post_type) && 'post' == $post->post_type )
|
if ( isset($post->post_type) && 'post' == $post->post_type )
|
||||||
$shortlink = home_url('?p=' . $post->ID);
|
$shortlink = home_url('?p=' . $post->ID);
|
||||||
|
@ -2105,7 +2105,7 @@ function wp_shortlink_wp_head() {
|
||||||
if ( empty($shortlink) )
|
if ( empty($shortlink) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
echo '<link rel="shortlink" href="' . $shortlink . '" />';
|
echo "<link rel='shortlink' href='" . $shortlink . "' />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2129,4 +2129,33 @@ function wp_shortlink_header() {
|
||||||
header('Link: <' . $shortlink . '>; rel=shortlink', false);
|
header('Link: <' . $shortlink . '>; rel=shortlink', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 $before Optional HTML to display after the link.
|
||||||
|
*/
|
||||||
|
function the_shortlink($text = '', $title = '', $before = '', $after = '') {
|
||||||
|
global $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) )
|
||||||
|
echo "$before<a rel='shortlink' href='$shortlink' title='$title'>$text</a>$after";
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue