the_shortlink

Displays the shortlink for a post.

Description

the_shortlink( (string) $text = '', (string) $title = '', (string) $before = '', (string) $after = '' ); 

Must be called from inside The Loop

Call like the_shortlink( __( Shortlinkage FTW ) )

Parameters (4)

0. $text — Optional. (string) => ''
The link text or HTML to be displayed. Defaults to This is the short link.
1. $title — Optional. (string) => ''
The tooltip for the link. Must be sanitized. Defaults to the sanitized post title.
2. $before — Optional. (string) => ''
HTML to display before the link. Default empty.
3. $after — Optional. (string) => ''
HTML to display after the link. Default empty.

Usage

  1. if ( !function_exists( 'the_shortlink' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional The link text or HTML to be displayed. Defaults to 'This is the short link.' 
  5. $text = ''; 
  6.  
  7. // Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title. 
  8. $title = ''; 
  9.  
  10. // Optional HTML to display before the link. Default empty. 
  11. $before = ''; 
  12.  
  13. // Optional HTML to display after the link. Default empty. 
  14. $after = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = the_shortlink($text, $title, $before, $after); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { 
  2. $post = get_post(); 
  3.  
  4. if ( empty( $text ) ) 
  5. $text = __('This is the short link.'); 
  6.  
  7. if ( empty( $title ) ) 
  8. $title = the_title_attribute( array( 'echo' => false ) ); 
  9.  
  10. $shortlink = wp_get_shortlink( $post->ID ); 
  11.  
  12. if ( !empty( $shortlink ) ) { 
  13. $link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; 
  14.  
  15. /** 
  16. * Filters the short link anchor tag for a post. 
  17. * @since 3.0.0 
  18. * @param string $link Shortlink anchor tag. 
  19. * @param string $shortlink Shortlink URL. 
  20. * @param string $text Shortlink's text. 
  21. * @param string $title Shortlink's title attribute. 
  22. */ 
  23. $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); 
  24. echo $before, $link, $after;