Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp get shortlink


Returns the Short Link to a post for use in PHP. It does NOT display the short link.


 <?php wp_get_shortlink(); ?> 


(integer) (optional) A post or blog id.
Default: Default is 0, which means the current post or blog.
(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'.
(bool) (optional) Whether to allow post slugs in the shortlink.
Default: It is up to the plugin how and whether to honor this.


Display the short link in plain text.

Short URL: http://example.com/?p=1234

 Short URL: <?php echo wp_get_shortlink(); ?> 

Source File

wp_get_shortlink() is located in wp-includes/link-template.php.