WordPress.org

Make WordPress Core

Changeset 21169


Ignore:
Timestamp:
06/28/2012 08:28:57 PM (9 years ago)
Author:
nacin
Message:

Add a post_link_category filter to the permalink generation process.

This allows a plugin to easily change which category gets represented
in the URL. Previously, it went off the category with the smallest ID.

props aaroncampbell
fixes #18752

File:
1 edited

Legend:

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

    r20944 r21169  
    123123            if ( $cats ) {
    124124                usort($cats, '_usort_terms_by_ID'); // order by ID
    125                 $category = $cats[0]->slug;
    126                 if ( $parent = $cats[0]->parent )
     125                $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
     126                $category_object = get_term( $category_object, 'category' );
     127                $category = $category_object->slug;
     128                if ( $parent = $category_object->parent )
    127129                    $category = get_category_parents($parent, false, '/', true) . $category;
    128130            }
Note: See TracChangeset for help on using the changeset viewer.