WordPress.org

Make WordPress Core

Ticket #14760: wp_get_shortlink.diff

File wp_get_shortlink.diff, 1.3 KB (added by sillybean, 9 years ago)

Generates p= shortlinks for all content types, not just posts.

  • wp-includes/link-template.php

     
    23582358 * Return a shortlink for a post, page, attachment, or blog.
    23592359 *
    23602360 * This function exists to provide a shortlink tag that all themes and plugins can target.  A plugin must hook in to
    2361  * provide the actual shortlinks.  Default shortlink support is limited to providing ?p= style links for posts.
     2361 * provide the actual shortlinks.  Default shortlink support is limited to providing ?p= style links.
    23622362 * Plugins can short circuit this function via the pre_get_shortlink filter or filter the output
    23632363 * via the get_shortlink filter.
    23642364 *
     
    23772377
    23782378        global $wp_query;
    23792379        $post_id = 0;
    2380         if ( 'query' == $context && is_single() ) {
     2380        if ( 'query' == $context && (is_single() || is_page()) ) {
    23812381                $post_id = $wp_query->get_queried_object_id();
    23822382        } elseif ( 'post' == $context ) {
    23832383                $post = get_post($id);
     
    23892389        // Return p= link for posts.
    23902390        if ( !empty($post_id) && '' != get_option('permalink_structure') ) {
    23912391                $post = get_post($post_id);
    2392                 if ( isset($post->post_type) && 'post' == $post->post_type )
     2392                if ( isset($post->post_type) )
    23932393                        $shortlink = home_url('?p=' . $post->ID);
    23942394        }
    23952395