Filter hook 'get_shortlink'

in WP Core File wp-includes/link-template.php at line 4200

View Source

get_shortlink

Filter Hook
Description
Filters the shortlink for a post.

Hook Information

File Location wp-includes/link-template.php View on GitHub
Hook Type Filter
Line Number 4200

Hook Parameters

Type Name Description
string $shortlink Shortlink URL.
int $id Post ID, or 0 for the current post.
string $context The context for the link. One of 'post' or 'query',
bool $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.

Usage Examples

Basic Usage
<?php
// Hook into get_shortlink
add_filter('get_shortlink', 'my_custom_filter', 10, 4);

function my_custom_filter($shortlink, $id, $context, $allow_slugs) {
    // Your custom filtering logic here
    return $shortlink;
}

Source Code Context

wp-includes/link-template.php:4200 - How this hook is used in WordPress core
<?php
4195  	 * @param string $shortlink   Shortlink URL.
4196  	 * @param int    $id          Post ID, or 0 for the current post.
4197  	 * @param string $context     The context for the link. One of 'post' or 'query',
4198  	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink. Not used by default.
4199  	 */
4200  	return apply_filters( 'get_shortlink', $shortlink, $id, $context, $allow_slugs );
4201  }
4202  
4203  /**
4204   * Injects rel=shortlink into the head if a shortlink is defined for the current page.
4205   *

PHP Documentation

<?php
/**
	 * Filters the shortlink for a post.
	 *
	 * @since 3.0.0
	 *
	 * @param string $shortlink   Shortlink URL.
	 * @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. Not used by default.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/link-template.php
Related Hooks

Related hooks will be displayed here in future updates.