Making WordPress.org


Ignore:
Timestamp:
10/26/2015 07:41:51 PM (9 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Accommodate deprecation of wp_title().

Note: Because the global W.org header requires the title to be passed via $GLOBALS['pagetitle'], add_theme_support( 'title-tag') can't be used.

  • Get title via wp_get_document_title() instead of wp_title().
  • Filter 'document_title_separator' to customize the title separator.
  • Hook 'wporg_developer_wp_title' to filter 'document_title_parts' instead of 'wp_title'.
  • Update wporg_developer_wp_title() to account for new args being passed to it.
  • Omit 'Home' from title of home page.

Props coffee2code, BandonRandon.
See #1353.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php

    r1475 r2010  
    3939 * Filters wp_title to print a neat <title> tag based on what is being viewed.
    4040 *
    41  * @param string $title Default title text for current view.
    42  * @param string $sep Optional separator.
    43  * @return string The filtered title.
     41 * @param array $parts The document title parts.
     42 * @return array The document title parts.
    4443 */
    45 function wporg_developer_wp_title( $title, $sep ) {
     44function wporg_developer_wp_title( $parts ) {
    4645    global $page, $paged;
    4746
    4847    if ( is_feed() ) {
    49         return $title;
     48        return $parts;
    5049    }
     50
     51    $title = $parts['title'];
     52    $sep = '|';
    5153
    5254    $post_type = get_query_var( 'post_type' );
    5355
     56    // Omit 'Home' from the home page.
     57    if ( 'Home' === $title ) {
     58        $title = '';
     59    }
    5460    // Add post type to title if it's a parsed item.
    55     if ( is_singular() && \DevHub\is_parsed_post_type( $post_type ) ) {
     61    elseif ( is_singular() && \DevHub\is_parsed_post_type( $post_type ) ) {
    5662        if ( $post_type_object = get_post_type_object( $post_type ) ) {
    57             $title .= get_post_type_object( $post_type )->labels->singular_name . " $sep ";
     63            $title .= " $sep " . get_post_type_object( $post_type )->labels->singular_name;
    5864        }
    5965    }
     
    6167    elseif ( is_singular() && false !== strpos( $post_type, 'handbook' ) ) {
    6268        if ( $post_type_object = get_post_type_object( $post_type ) ) {
    63             $handbook_label = get_post_type_object( $post_type )->labels->name . " $sep ";
    64             $handbook_name  = \WPorg_Handbook::get_name( $post_type ) . " Handbook $sep ";
     69            $handbook_label = " $sep " . get_post_type_object( $post_type )->labels->name;
     70            $handbook_name  = " $sep " . \WPorg_Handbook::get_name( $post_type ) . " Handbook";
    6571
    6672            // Replace title with handbook name if this is landing page for the handbook
     
    7581
    7682    // Add a page number if necessary:
    77     if ( $paged >= 2 || $page >= 2 ) {
    78         $title .= sprintf( __( 'Page %s', 'wporg' ), max( $paged, $page ) ) . " $sep ";
     83    if ( isset( $parts['page'] ) && $parts['page'] >= 2 ) {
     84        $title .= " $sep " . sprintf( __( 'Page %s', 'wporg' ), $parts['page'] );
    7985    }
    8086
    81     // Add the blog name
    82     $title .= get_bloginfo( 'name' );
    83 
    84     return $title;
     87    $parts['title'] = $title;
     88    return $parts;
    8589}
    86 add_filter( 'wp_title', 'wporg_developer_wp_title', 10, 2 );
     90add_filter( 'document_title_parts', 'wporg_developer_wp_title' );
    8791
    8892/**
Note: See TracChangeset for help on using the changeset viewer.