pre_get_shortlink
Filters whether to preempt generating a shortlink for the given post.
Returning a value other than false from the filter will short-circuit the shortlink generation process, returning that value instead.
Usage
add_filter( 'pre_get_shortlink', 'wp_kama_pre_get_shortlink_filter', 10, 4 );
/**
* Function for `pre_get_shortlink` filter-hook.
*
* @param false|string $return Short-circuit return value. Either false or a URL string.
* @param int $id Post ID, or 0 for the current post.
* @param string $context The context for the link. One of 'post' or 'query',
* @param bool $allow_slugs Whether to allow post slugs in the shortlink.
*
* @return false|string
*/
function wp_kama_pre_get_shortlink_filter( $return, $id, $context, $allow_slugs ){
// filter...
return $return;
}
- $return(false|string)
- Short-circuit return value. Either false or a URL string.
- $id(int)
- Post ID, or 0 for the current post.
- $context(string)
- The context for the link. One of 'post' or 'query',
- $allow_slugs(true|false)
- Whether to allow post slugs in the shortlink.
Changelog
| Since 3.0.0 | Introduced. |
Where the hook is called
pre_get_shortlink
wp-includes/link-template.php 4167
$shortlink = apply_filters( 'pre_get_shortlink', false, $id, $context, $allow_slugs );