Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#36198 closed defect (bug) (wontfix)

wp_shortlink_wp_head should exit on non-singles and frontpage

Reported by: andrejcremoznik Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Permalinks Keywords:
Focuses: Cc:


There is no need for shortlinks on archives and front page.

The default function which outputs shortlink markup should check if the displayed content is a single post or page but not a static front page before outputting anything.

This is what I use instead of the default wp_shortlink_wp_head.

function print_shortlink() {
    $shortlink = wp_get_shortlink(0, 'query');
    if (empty($shortlink) || is_front_page() || (!is_single() && !is_page()))
    echo "<link rel='shortlink' href='" . esc_url($shortlink) . "'>\n";

Change History (1)

#1 @swissspidy
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
  • Version changed from 4.4.2 to 3.0

The return value of wp_get_shortlink() can be filtered. It's possible that someone's creating a shortlink for archives and other areas. If not, that function returns an empty string, which wp_shortlink_wp_head() checks for. This behaviour shouldn't be changed, otherwise it would break BC.

Note: See TracTickets for help on using tickets.