the_shortlink

函式
the_shortlink ( $text = '', $title = '', $before = '', $after = '' )
引數
  • (string) $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.'
    Required:
    Default: (empty)
  • (string) $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
    Required:
    Default: (empty)
  • (string) $before Optional HTML to display before the link. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional HTML to display after the link. Default empty.
    Required:
    Default: (empty)
定義位置
相關方法
the_author_linkwp_get_shortlinkget_shortcut_linkthe_author_posts_linkget_the_author_link
引入
3.0.0
棄用
-

shortlink是一個WordPress函式,用於檢索當前文章或指定文章的短連結。它可以用於為使用者提供一個縮短的URL,以便在社交媒體上輕鬆共享。

顯示一個文章的短連結。

必須從”The Loop”中呼叫。

像the_shortlink( __( ‘Shortlinkage FTW’) 這樣呼叫。)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
}
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; } }
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;
	}
}

常見問題

FAQs
檢視更多 >