Make WordPress Core

Changeset 60994

Timestamp:
10/20/2025 10:11:23 PM (5 weeks ago)
Author:
jorbin
Message:

Themes: Add a new taxonomy template.

This uses the same cascade as tags and categories so the check will first be for the slug first, then the term ID,

In classic themes, you can now use term IDs when creating taxonomy templates. With taxonomy-$taxonomy-{$term->term_id}.php templates you don't need to worry about templates breaking if you rename the Oakland Athletics term to Athletics the way you do if you use slug based template names.

Props swissspidy, sebastian.pisula, jorbin, theMikeD.
Fixes #35326.

File:
1 edited

Legend:

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

    r60973 r60994  
    324324 *
    325325 * 1. taxonomy-{taxonomy_slug}-{term_slug}.php
    326  * 2. taxonomy-{taxonomy_slug}.php
    327  * 3. taxonomy.php
     326 * 2. taxonomy-{taxonomy_slug}-{term_id}.php
     327 * 3. taxonomy-{taxonomy_slug}.php
     328 * 4. taxonomy.php
    328329 *
    329330 * An example of this is:
    330331 *
    331332 * 1. taxonomy-location-texas.php
    332  * 2. taxonomy-location.php
    333  * 3. taxonomy.php
     333 * 2. taxonomy-location-67.php
     334 * 3. taxonomy-location.php
     335 * 4. taxonomy.php
    334336 *
    335337 * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
     
    339341 * @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the
    340342 *              template hierarchy when the term slug contains multibyte characters.
     343 * @since 6.9.0 Added `taxonomy-{taxonomy_slug}-{term_id}.php` to the hierarchy.
    341344 *
    342345 * @see get_query_template()
     
    358361
    359362        $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
     363        $templates[] = "taxonomy-$taxonomy-{$term->term_id}.php";
    360364        $templates[] = "taxonomy-$taxonomy.php";
    361365    }
Note: See TracChangeset for help on using the changeset viewer.