From 97e35590790306671f4c0d4683563805b9af4ea7 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 12 Mar 2010 16:08:37 +0000 Subject: [PATCH] the_shortlink(). Props miqrogroove. fixes #10640 git-svn-id: http://svn.automattic.com/wordpress/trunk@13683 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 53a2dc84ef..72c4d8545d 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -2081,7 +2081,7 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) { $shortlink = ''; // Return p= link for posts. - if ( !empty($post_id) ) { + if ( !empty($post_id) && '' != get_option('permalink_structure') ) { $post = get_post($post_id); if ( isset($post->post_type) && 'post' == $post->post_type ) $shortlink = home_url('?p=' . $post->ID); @@ -2105,7 +2105,7 @@ function wp_shortlink_wp_head() { if ( empty($shortlink) ) return; - echo ''; + echo "\n"; } /** @@ -2129,4 +2129,33 @@ function wp_shortlink_header() { 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$text$after"; +} + ?>