wp_get_shortlink

SummerySummery

Returns a shortlink for a post, page, attachment, or site.

Syntax

wp_get_shortlink( int $id, string $context = 'post', bool $allow_slugs = true )

DescriptionDescription

This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. Plugins can short-circuit this function via the ‘pre_get_shortlink’ filter or filter the output via the ‘get_shortlink’ filter.

ParametersParameters

$id

(int) (Optional) A post or site id. Default is 0, which means the current post or site.

$context

(string) (Optional) Whether the id is a 'site' 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 value: 'post'

$allow_slugs

(bool) (Optional) Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.

Default value: true

ReturnReturn

(string) A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.

SourceSource

File: wp-includes/link-template.php


			

ChangelogChangelog

Changelog
Version Description
3.0.0 Introduced.
Scroll to Top