Make WordPress Core


Ignore:
Timestamp:
09/29/2015 09:41:14 AM (10 years ago)
Author:
pento
Message:

Permalinks: Add pretty permalinks for unattached attachments.

Previously, unattached attachments would have unsightly /?attachment_id=1 URLs. As we've moved away from attachments being specifically attached to posts, instead being Media items, this has made the unattached URLs a more common occurrence.

We can breath easy once more, knowing that the world is a little bit safer from the horror of unnecessarily ugly URLs.

Props SergeyBiryukov, wonderboymusic, pento.

Fixes #1914.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r34561 r34690  
    387387    $post = get_post( $post );
    388388    $parent = ( $post->post_parent > 0 && $post->post_parent != $post->ID ) ? get_post( $post->post_parent ) : false;
     389    if ( $parent && ! in_array( $parent->post_type, get_post_types() ) ) {
     390        $parent = false;
     391    }
    389392
    390393    if ( $wp_rewrite->using_permalinks() && $parent ) {
     
    404407        if ( ! $leavename )
    405408            $link = str_replace( '%postname%', $name, $link );
     409    } elseif ( $wp_rewrite->using_permalinks() && ! $leavename ) {
     410        $link = home_url( user_trailingslashit( $post->post_name ) );
    406411    }
    407412
Note: See TracChangeset for help on using the changeset viewer.