Making WordPress.org


Ignore:
Timestamp:
04/15/2020 10:12:33 PM (5 years ago)
Author:
coffee2code
Message:

Developer theme: Centralize page HEAD-related customizations into recently added inc/head.php file.

File:
1 edited

Legend:

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

    r9325 r9733  
    3535}
    3636add_filter( 'body_class', 'wporg_developer_body_classes' );
    37 
    38 /**
    39  * Filters document title to add context based on what is being viewed.
    40  *
    41  * @param array $parts The document title parts.
    42  * @return array The document title parts.
    43  */
    44 function wporg_developer_document_title( $parts ) {
    45     global $page, $paged;
    46 
    47     if ( is_feed() ) {
    48         return $parts;
    49     }
    50 
    51     $title = $parts['title'];
    52     $sep = '|';
    53 
    54     $post_type = get_query_var( 'post_type' );
    55 
    56     // Omit 'Home' from the home page.
    57     if ( 'Home' === $title ) {
    58         $title = '';
    59     }
    60     // Add post type to title if it's a parsed item.
    61     elseif ( is_singular() && \DevHub\is_parsed_post_type( $post_type ) ) {
    62         if ( $post_type_object = get_post_type_object( $post_type ) ) {
    63             $title .= " $sep " . get_post_type_object( $post_type )->labels->singular_name;
    64         }
    65     }
    66     // Add handbook name to title if relevent
    67     elseif ( ( is_singular() || is_post_type_archive() ) && false !== strpos( $post_type, 'handbook' ) ) {
    68         if ( $post_type_object = get_post_type_object( $post_type ) ) {
    69             $handbook_label = get_post_type_object( $post_type )->labels->name;
    70             $handbook_name  = \WPorg_Handbook::get_name( $post_type ) . " Handbook";
    71 
    72             // Replace title with handbook name if this is landing page for the handbook
    73             if ( $title == $handbook_label ) {
    74                 $title = $handbook_name;
    75             // Otherwise, append the handbook name
    76             } else {
    77                 $title .= " $sep " . $handbook_name;
    78             }
    79         }
    80     }
    81 
    82     // Add a page number if necessary:
    83     if ( isset( $parts['page'] ) && $parts['page'] >= 2 ) {
    84         $title .= " $sep " . sprintf( __( 'Page %s', 'wporg' ), $parts['page'] );
    85     }
    86 
    87     $parts['title'] = $title;
    88     return $parts;
    89 }
    90 add_filter( 'document_title_parts', 'wporg_developer_document_title' );
    9137
    9238/**
Note: See TracChangeset for help on using the changeset viewer.