Changeset 9733
- Timestamp:
- 04/15/2020 10:12:33 PM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r9717 r9733 167 167 add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_handbook_root', 10, 2 ); 168 168 169 add_filter( 'document_title_separator', __NAMESPACE__ . '\\theme_title_separator', 10, 2 );170 171 169 add_filter( 'syntaxhighlighter_htmlresult', __NAMESPACE__ . '\\syntaxhighlighter_htmlresult' ); 172 }173 174 /**175 * Customize the theme title separator.176 *177 * @return string178 */179 function theme_title_separator(){180 return '|';181 170 } 182 171 … … 420 409 } 421 410 422 /**423 * Outputs `<link rel="canonical">` tags where appropriate.424 */425 function rel_canonical() {426 $canonical = false;427 $queried_object = get_queried_object();428 429 if ( is_tax() || is_tag() || is_category() ) {430 $canonical = get_term_link( $queried_object );431 } elseif ( is_post_type_archive() ) {432 $canonical = get_post_type_archive_link( $queried_object->name );433 }434 435 if ( $canonical && get_query_var( 'paged' ) > 1 ) {436 $canonical .= 'page/' . (int) get_query_var( 'paged' ) . '/';437 }438 439 if ( $canonical ) {440 printf( '<link rel="canonical" href="%s">' . "\n", esc_url( $canonical ) );441 }442 }443 add_action( 'wp_head', __NAMESPACE__ . '\rel_canonical', 9 );444 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php
r9325 r9733 35 35 } 36 36 add_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 relevent67 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 handbook73 if ( $title == $handbook_label ) {74 $title = $handbook_name;75 // Otherwise, append the handbook name76 } 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' );91 37 92 38 /** -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/head.php
r9715 r9733 22 22 */ 23 23 public static function do_init() { 24 add_action( 'wp_head', array( __CLASS__, 'output_head_tags' ), 2 ); 24 add_filter( 'document_title_parts', array( __CLASS__, 'document_title' ) ); 25 add_filter( 'document_title_separator', array( __CLASS__, 'document_title_separator' ) ); 26 add_action( 'wp_head', array( __CLASS__, 'rel_canonical' ), 9 ); 27 add_action( 'wp_head', array( __CLASS__, 'output_head_tags' ), 2 ); 28 } 29 30 /** 31 * Filters document title to add context based on what is being viewed. 32 * 33 * @param array $parts The document title parts. 34 * @return array The document title parts. 35 */ 36 public static function document_title( $parts ) { 37 global $page, $paged; 38 39 if ( is_feed() ) { 40 return $parts; 41 } 42 43 $title = $parts['title']; 44 $sep = '|'; 45 46 $post_type = get_query_var( 'post_type' ); 47 48 // Omit 'Home' from the home page. 49 if ( 'Home' === $title ) { 50 $title = ''; 51 } 52 // Add post type to title if it's a parsed item. 53 elseif ( is_singular() && \DevHub\is_parsed_post_type( $post_type ) ) { 54 if ( $post_type_object = get_post_type_object( $post_type ) ) { 55 $title .= " $sep " . get_post_type_object( $post_type )->labels->singular_name; 56 } 57 } 58 // Add handbook name to title if relevent 59 elseif ( ( is_singular() || is_post_type_archive() ) && false !== strpos( $post_type, 'handbook' ) ) { 60 if ( $post_type_object = get_post_type_object( $post_type ) ) { 61 $handbook_label = get_post_type_object( $post_type )->labels->name; 62 $handbook_name = \WPorg_Handbook::get_name( $post_type ) . " Handbook"; 63 64 // Replace title with handbook name if this is landing page for the handbook 65 if ( $title == $handbook_label ) { 66 $title = $handbook_name; 67 // Otherwise, append the handbook name 68 } else { 69 $title .= " $sep " . $handbook_name; 70 } 71 } 72 } 73 74 // Add a page number if necessary: 75 if ( isset( $parts['page'] ) && $parts['page'] >= 2 ) { 76 $title .= " $sep " . sprintf( __( 'Page %s', 'wporg' ), $parts['page'] ); 77 } 78 79 $parts['title'] = $title; 80 81 return $parts; 82 } 83 84 /** 85 * Customizes the document title separator. 86 * 87 * @param string $separator Current document title separator. 88 * @return string 89 */ 90 public static function document_title_separator( $separator ) { 91 return '|'; 25 92 } 26 93 … … 108 175 } 109 176 177 /** 178 * Outputs `<link rel="canonical">` tags where appropriate. 179 */ 180 public static function rel_canonical() { 181 $canonical = false; 182 $queried_object = get_queried_object(); 183 184 if ( is_tax() || is_tag() || is_category() ) { 185 $canonical = get_term_link( $queried_object ); 186 } elseif ( is_post_type_archive() ) { 187 $canonical = get_post_type_archive_link( $queried_object->name ); 188 } 189 190 if ( $canonical && get_query_var( 'paged' ) > 1 ) { 191 $canonical .= 'page/' . (int) get_query_var( 'paged' ) . '/'; 192 } 193 194 if ( $canonical ) { 195 printf( '<link rel="canonical" href="%s">' . "\n", esc_url( $canonical ) ); 196 } 197 } 198 110 199 } // DevHub_Head 111 200
Note: See TracChangeset
for help on using the changeset viewer.