Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#30973 closed enhancement (worksforme)

Add post type support for adjacent links

Reported by: jfarthing84's profile jfarthing84 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch close
Focuses: Cc:


I can't tell you how much time I've wasted over the years tracking down bugs caused by Firefox prefetching adjacent post links. Let's face it, most custom post types do not need this feature. I'm proposing adding a post type support, 'adjacent-links', to enable/disable this feature.

Attachments (1)

30973.patch (1.6 KB) - added by jfarthing84 9 years ago.
Add 'adjacent-links' post type support

Download all attachments as: .zip

Change History (5)

9 years ago

Add 'adjacent-links' post type support

#1 @jfarthing84
9 years ago

  • Keywords has-patch added

#2 @wonderboymusic
9 years ago

  • Keywords close added

This would be best handled in the theme - conditionally turning off:

add_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );

#3 @jfarthing84
9 years ago

The function adjacent_posts_rel_link_wp_head() itself conditionally checks for specific post types. How again is this something that should be handled at a theme level?

#4 @wonderboymusic
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
add_action( 'template_redirect', function () {
    $types = [ 'foo, 'bar' ]; 
    if ( ! is_single() || ! in_array( get_query_var( 'post_type'  ), $types ) ) {

    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); 

    // OR

     //  this assumes you already called `add_post_type_support( 'foo', 'adjacent-links' );`
    if ( post_type_supports( get_query_var( 'post_type'  ), 'adjacent-links' ) ) {
        remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); 

} );

UI elements (<link>s in this case) that appear on the front-end have nothing to do with post_type registration - BUT, you could easily add the value to supports and then check for that support here. So, what you are proposing already exists, it would be up to the theme to implement it anyways. We can't turn off global support for all post types and require people to add new code to turn them on. That could potentially break expected behavior for themes.

Seems like you might just need this anyways:
<meta http-equiv="x-dns-prefetch-control" content="off" />

Note: See TracTickets for help on using tickets.