WordPress.org

Make WordPress Core

Ticket #38545: 38545.11.diff

File 38545.11.diff, 5.6 KB (added by audrasjb, 11 months ago)

Patch refreshed so hopefully it can land in 4.9.9

  • src/wp-includes/general-template.php

    diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
    index 331d1f2..3fc2015 100644
    a b function single_month_title( $prefix = '', $display = true ) { 
    14711471 * Display the archive title based on the queried object.
    14721472 *
    14731473 * @since 4.1.0
     1474 * @since 4.9.9 Added $span_class parameter.
    14741475 *
    14751476 * @see get_the_archive_title()
    14761477 *
    1477  * @param string $before Optional. Content to prepend to the title. Default empty.
    1478  * @param string $after  Optional. Content to append to the title. Default empty.
     1478 * @param string $before     Optional. Content to prepend to the title. Default empty.
     1479 * @param string $after      Optional. Content to append to the title. Default empty.
     1480 * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    14791481 */
    1480 function the_archive_title( $before = '', $after = '' ) {
    1481         $title = get_the_archive_title();
     1482function the_archive_title( $before = '', $after = '', $span_class = '' ) {
     1483        $title = get_the_archive_title( $span_class );
    14821484
    14831485        if ( ! empty( $title ) ) {
    14841486                echo $before . $title . $after;
    function the_archive_title( $before = '', $after = '' ) { 
    14891491 * Retrieve the archive title based on the queried object.
    14901492 *
    14911493 * @since 4.1.0
     1494 * @since 4.9.9 Added $span_class parameter.
    14921495 *
     1496 * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    14931497 * @return string Archive title.
    14941498 */
    1495 function get_the_archive_title() {
     1499function get_the_archive_title( $span_class = '' ) {
    14961500        if ( is_category() ) {
    1497                 /* translators: Category archive title. %s: Category name */
    1498                 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
     1501                /* translators: Category archive title. */
     1502                $type = __( 'Category:' );
     1503                $name = single_cat_title( '', false );
    14991504        } elseif ( is_tag() ) {
    1500                 /* translators: Tag archive title. %s: Tag name */
    1501                 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
     1505                /* translators: Tag archive title. */
     1506                $type = __( 'Tag:' );
     1507                $name = single_tag_title( '', false );
    15021508        } elseif ( is_author() ) {
    1503                 /* translators: Author archive title. %s: Author name */
    1504                 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
     1509                /* translators: Author archive title. */
     1510                $type = __( 'Author:' );
     1511                /* translators: %s: Author name. */
     1512                $name = sprintf( '<span class="vcard">%s</span>', get_the_author() );
    15051513        } elseif ( is_year() ) {
    1506                 /* translators: Yearly archive title. %s: Year */
    1507                 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
     1514                /* translators: Yearly archive title. */
     1515                $type = __( 'Year:' );
     1516                $name = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    15081517        } elseif ( is_month() ) {
    1509                 /* translators: Monthly archive title. %s: Month name and year */
    1510                 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
     1518                /* translators: Monthly archive title. */
     1519                $type = __( 'Month:' );
     1520                $name = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    15111521        } elseif ( is_day() ) {
    1512                 /* translators: Daily archive title. %s: Date */
    1513                 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
    1514         } elseif ( is_tax( 'post_format' ) ) {
     1522                /* translators: Daily archive title. */
     1523                $type = __( 'Day:' );
     1524                $name = get_the_date( _x( 'F j, Y', 'daily archives date format' ) );
     1525        } elseif ( is_post_type_archive() ) {
     1526                /* translators: Post type archive title. */
     1527                $type = __( 'Archives:' );
     1528                $name = post_type_archive_title( '', false );
     1529        } elseif ( is_tax() ) {
     1530                $tax = get_taxonomy( get_queried_object()->taxonomy );
     1531                /* translators: Taxonomy singular name */
     1532                $type = sprintf( __( '%s:' ), $tax->labels->singular_name );
     1533                $name = single_term_title( '', false );
     1534        }
     1535       
     1536        if ( is_tax( 'post_format' ) ) {
    15151537                if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    15161538                        $title = _x( 'Asides', 'post format archive title' );
    15171539                } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
    function get_the_archive_title() { 
    15311553                } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    15321554                        $title = _x( 'Chats', 'post format archive title' );
    15331555                }
    1534         } elseif ( is_post_type_archive() ) {
    1535                 /* translators: Post type archive title. %s: Post type name */
    1536                 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
    1537         } elseif ( is_tax() ) {
    1538                 $tax = get_taxonomy( get_queried_object()->taxonomy );
    1539                 /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
    1540                 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
     1556        } elseif ( isset( $type ) && isset( $name ) ) {
     1557                if ( ! empty( $span_class ) ) {
     1558                        $span_class = sprintf( ' class="%s"', esc_attr( $span_class ) );
     1559                        $title = sprintf( '<span%s>%s </span>%s', $span_class, $type, $name );
     1560                } else {
     1561                        $title = sprintf( '%s %s', $type, $name );
     1562                }
    15411563        } else {
    15421564                $title = __( 'Archives' );
    15431565        }
    function get_the_archive_title() { 
    15461568         * Filters the archive title.
    15471569         *
    15481570         * @since 4.1.0
     1571         * @since 4.9.9 Added $span_class parameter.
    15491572         *
    15501573         * @param string $title Archive title to be displayed.
     1574         * @param string $span_class Optional. Class name to apply to the span around the archive type description. Default empty.
    15511575         */
    1552         return apply_filters( 'get_the_archive_title', $title );
     1576        return apply_filters( 'get_the_archive_title', $title, $span_class );
    15531577}
    15541578
    15551579/**