get_shortlink

Filters the shortlink for a post.

Description

apply_filters( 'get_shortlink', (string) $shortlink, (int) $id, (string) $context, (bool) $allow_slugs ); 

Parameters (4)

0. $shortlink (string)
The shortlink.
1. $id (int)
Post ID, or 0 for the current post.
2. $context (string)
The context for the link. One of post or query,,
3. $allow_slugs (bool)
Whether to allow post slugs in the shortlink. Not used by default.

Usage

To run the hook, copy the example below.
  1. $shortlink = apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs ); 
  2.  
  3. if ( !empty( $shortlink ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the get_shortlink callback 
  2. function filter_get_shortlink( $shortlink, $id, $context, $allow_slugs ) { 
  3. // make filter magic happen here... 
  4. return $shortlink
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'get_shortlink', 'filter_get_shortlink', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'get_shortlink', 'filter_get_shortlink', 10, 4 ); 

Defined (1)

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

/wp-includes/link-template.php  
  1. return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );