WordPress.org

Making WordPress.org

Changeset 2077


Ignore:
Timestamp:
11/11/2015 08:18:51 PM (4 years ago)
Author:
coffee2code
Message:

W.org Showcase: Handle deprecation of wp_title().

  • Get title via wp_get_document_title() instead of wp_title().
  • Hook 'document_title_parts' to customize document title rather than doing so in header.php.
  • Adjust breadcrumb to use wp_get_document_title() instead of wp_title().
  • Filter 'document_title_separator' to customize the title separator.
  • Omit front page's title ('Home') from front page document title.

See #1353.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-showcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-showcase/functions.php

    r1709 r2077  
    152152            <?php endif; // is_category ?>
    153153
    154         <?php echo wp_title(); ?>
     154            &raquo; <?php echo wp_get_document_title(); ?>
    155155        <?php endif; // is_search ?>
    156156
     
    231231add_filter( 'excerpt_more', create_function( '$more', 'return "...";' ) );
    232232
    233 
     233/**
     234 * Filters document title to add context based on what is being viewed.
     235 *
     236 * @param array  $parts The document title parts.
     237 * @return array The document title parts.
     238 */
     239function wporg_showcase_document_title( $parts ) {
     240    // wp_get_document_title() is used by the theme in breadcrumb(), whereby it
     241    // only really needs the title.
     242    if ( did_action( 'wp_head' ) ) {
     243        return array( 'title' => $parts['title'] );
     244    }
     245
     246    if ( is_front_page() ) {
     247        // Omit page name from the home page.
     248        $parts['title'] = '';
     249    } elseif ( is_category() ) {
     250        // Prepend 'Flavor: ' to category document titles.
     251        $parts['title'] = 'Flavor: ' . $parts['title'];
     252    } elseif ( is_tag() ) {
     253        // Prepend 'Tag: ' to tag document titles.
     254        $parts['title'] = 'Tag: ' . $parts['title'];
     255    }
     256
     257    return $parts;
     258}
     259add_filter( 'document_title_parts', 'wporg_showcase_document_title' );
     260
     261// Change the document title separator.
     262add_filter( 'document_title_separator', create_function( '$separator', 'return "&#8250;";' ) );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-showcase/header.php

    r1902 r2077  
    11<?php
    2 global $pagetitle;
    3 
    4 if ( is_single() )
    5     $pagetitle = 'Showcase &raquo; ' . wp_title( '', false );
    6 elseif ( is_category() )
    7     $pagetitle = 'Showcase &raquo; Flavor &raquo; ' . wp_title( '', false );
    8 elseif ( is_tag() )
    9     $pagetitle = 'Showcase &raquo; Tag &raquo; ' . wp_title( '', false );
     2$GLOBALS['pagetitle'] = wp_get_document_title();
    103
    114$prefix = is_ssl() ? 'https://' : 'http://s.';
Note: See TracChangeset for help on using the changeset viewer.