pre_get_shortlink

Filters whether to preempt generating a shortlink for the given post.

Description

apply_filters( 'pre_get_shortlink', (bool) $false, (int) $id, (string) $context, (bool) $allow_slugs ); 

Passing a truthy value to the filter will effectively short-circuit the shortlink-generation process, returning that value instead.

Parameters (4)

0. $false (bool) => false
Short-circuit return value. Either false or a URL string.
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.

Usage

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

Defined (1)

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

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