Function Reference/wp get shortlink
Description
Returns the Short Link to a post for use in PHP. It does NOT display the short link.
Usage
<?php wp_get_shortlink(); ?>
Parameters
- $id
- (integer) (optional) A post or blog id.
- Default: Default is 0, which means the current post or blog.
- $context
- (string) (optional) Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context.
- Default: Default is 'post'.
- $allow_slugs
- (bool) (optional) Whether to allow post slugs in the shortlink.
- Default: It is up to the plugin how and whether to honor this.
Examples
Display the short link in plain text.
Short URL: <?php echo wp_get_shortlink(); ?>
Source File
wp_get_shortlink() is located in wp-includes/link-template.php.