wp_shortlink_header()WP 3.0.0

Creates a header response Link: rel=shortlink in which the value is set to the short link for the current пост.

Triggered on the hook template_redirect:

add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );

No Hooks.

Returns

null. Nothing (null).

Usage

wp_shortlink_header();

Examples

0

#1 Remove the short link to the current post from the server response header

remove_action( 'template_redirect', 'wp_shortlink_header', 11 );

Changelog

Since 3.0.0 Introduced.

wp_shortlink_header() code WP 7.0

function wp_shortlink_header() {
	if ( headers_sent() ) {
		return;
	}

	$shortlink = wp_get_shortlink( 0, 'query' );

	if ( empty( $shortlink ) ) {
		return;
	}

	header( 'Link: <' . $shortlink . '>; rel=shortlink', false );
}