Ticket #18548: title-template-system.diff
File title-template-system.diff, 14.9 KB (added by , 13 years ago) |
---|
-
wp-content/themes/twentyeleven/functions.php
108 108 // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images 109 109 add_theme_support( 'post-thumbnails' ); 110 110 111 // Add support for new title system 112 add_theme_support( 'title-tag', array( 'sep' => ' | ' ) ); 113 111 114 // Add support for custom headers. 112 115 add_theme_support( 'custom-header', array( 113 116 // The default header text color. -
wp-content/themes/twentyeleven/header.php
24 24 <head> 25 25 <meta charset="<?php bloginfo( 'charset' ); ?>" /> 26 26 <meta name="viewport" content="width=device-width" /> 27 <title><?php28 /*29 * Print the <title> tag based on what is being viewed.30 */31 global $page, $paged;32 33 wp_title( '|', true, 'right' );34 35 // Add the blog name.36 bloginfo( 'name' );37 38 // Add the blog description for the home/front page.39 $site_description = get_bloginfo( 'description', 'display' );40 if ( $site_description && ( is_home() || is_front_page() ) )41 echo " | $site_description";42 43 // Add a page number if necessary:44 if ( $paged >= 2 || $page >= 2 )45 echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );46 47 ?></title>48 27 <link rel="profile" href="http://gmpg.org/xfn/11" /> 49 28 <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> 50 29 <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> -
wp-content/themes/twentyten/functions.php
84 84 // Add default posts and comments RSS feed links to head 85 85 add_theme_support( 'automatic-feed-links' ); 86 86 87 // Add support for new title system 88 add_theme_support( 'title-tag', array( 'sep' => ' | ' ) ); 89 87 90 // Make theme available for translation 88 91 // Translations can be filed in the /languages/ directory 89 92 load_theme_textdomain( 'twentyten', get_template_directory() . '/languages' ); -
wp-content/themes/twentyten/header.php
12 12 <html <?php language_attributes(); ?>> 13 13 <head> 14 14 <meta charset="<?php bloginfo( 'charset' ); ?>" /> 15 <title><?php16 /*17 * Print the <title> tag based on what is being viewed.18 */19 global $page, $paged;20 21 wp_title( '|', true, 'right' );22 23 // Add the blog name.24 bloginfo( 'name' );25 26 // Add the blog description for the home/front page.27 $site_description = get_bloginfo( 'description', 'display' );28 if ( $site_description && ( is_home() || is_front_page() ) )29 echo " | $site_description";30 31 // Add a page number if necessary:32 if ( $paged >= 2 || $page >= 2 )33 echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );34 35 ?></title>36 15 <link rel="profile" href="http://gmpg.org/xfn/11" /> 37 16 <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> 38 17 <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> -
wp-includes/general-template.php
617 617 } 618 618 619 619 /** 620 * Display <title> tag with contents 621 * 622 * When using add_theme_support to add support for this function, one can set a few variables: 623 * 'sep' string, for the separator used in title tags 624 * 'home-title' string, for the homepage title. Only used for the blog page when the blog page is also the frontpage. 625 * 'frontpage-title' string, for the front page when it's not the posts page. 626 * 'show-sitename' boolean, defaults to true. When set to false the site name will not be added to titles. 627 * 628 * @since 3.4.0 629 * @access private 630 */ 631 function _wp_render_title_tag() { 632 if ( ! current_theme_supports( 'title-tag' ) ) 633 return; 634 635 // This can only work internally on wp_head. 636 if ( ! did_action( 'wp_head' ) && ( ! function_exists( 'doing_action' ) || ! doing_action( 'wp_head' ) ) ) 637 return; 638 639 // If wp_title() has fired, don't do anything. 640 if ( did_action( 'wp_title' ) ) 641 return; 642 643 // Allow early filtering, if this returns a title skip all the logic below 644 // and print it. 645 if ( null !== $pre = apply_filters( 'pre_wp_title_tag', null ) ) { 646 echo "<title>$pre</title>\n"; 647 return; 648 } 649 650 global $page, $paged; 651 652 // Retrieve the options set by the add_theme_support call. The 653 // title_tag_options_filter filter allows any interested code to modify the 654 // set options easily. 655 $options = get_theme_support( 'title-tag' ); 656 $options = apply_filters( 'title_tag_options_filter', $options[0] ); 657 658 // ltr language sites tend to use title that has the most-specific part of 659 // the title on the left. rtl language sites tend to reverse this. The auto 660 // option automatically selects the appropriate direction based upon whether 661 // the site is set to use a text direction of ltr or rtl. This can be 662 // directly overridden by supplying ltr or rtl. 663 if ( 'auto' == $options['direction'] || ! in_array( $options['direction'], array( 'ltr', 'rtl' ) ) ) 664 $options['direction'] = is_rtl() ? 'rtl' : 'ltr'; 665 666 // Set up the PAGING variable. 667 if ( empty( $options['variables']['PAGING'] ) ) 668 $options['variables']['PAGING'] = '%1$d'; 669 if ( $paged >= 2 || $page >= 2 ) 670 $options['variables']['PAGING'] = sprintf( $options['variables']['PAGING'], max( $paged, $page ) ); 671 else 672 $options['variables']['PAGING'] = ''; 673 674 // Allow for a filter to set the title 675 if ( null !== $title = apply_filters( 'title_tag_filter', null ) ) { 676 if ( is_array($title) ) 677 list( $title, $view ) = $title; 678 else 679 $view = 'filter'; 680 // Standard home page view 681 } elseif ( is_home() && is_front_page() ) { 682 $title = get_bloginfo('name'); 683 $view = 'home'; 684 // Static Posts Page 685 } elseif ( is_home() && !is_front_page() ) { 686 $_post = get_post( get_option('page_for_posts') ); 687 $title = $_post->post_title; 688 $view = array( 'blog', 'page' ); 689 // Static Front Page 690 } elseif ( !is_home() && is_front_page() ) { 691 $title = single_post_title( '', false ); 692 $view = array( 'frontpage', 'page' ); 693 // Post, Page, Attachment 694 } else if ( is_singular() ) { 695 $title = single_post_title( '', false ); 696 $_post = get_queried_object(); 697 $view = array( $_post->post_type . '-singular', 'singular' ); 698 } 699 // Category or Tag Archive 700 elseif ( is_category() || is_tag() ) { 701 $title = single_term_title( '', false ); 702 $term = get_queried_object(); 703 $view = array( $term->taxonomy . '-taxonomy-archive', 'taxonomy-archive', 'archive' ); 704 } 705 // Taxonomy Archive 706 elseif ( is_tax() ) { 707 $term = get_queried_object(); 708 $tax = get_taxonomy( $term->taxonomy ); 709 $title = single_term_title( $tax->labels->name, false ); 710 $view = array( $term->taxonomy . '-taxonomy-archive', 'taxonomy-archive', 'archive' ); 711 } 712 // Author Archive 713 elseif ( is_author() ) { 714 $author = get_queried_object(); 715 $title = $author->display_name; 716 $view = array( 'author-archive', 'archive' ); 717 } 718 // Post Type Archive 719 elseif ( is_post_type_archive() ) { 720 $title = post_type_archive_title( '', false ); 721 $_post = get_queried_object(); 722 $view = array( $_post->query_var . '-post-type-archive', 'post-type-archive', 'archive' ); 723 } 724 // Date Archive 725 elseif ( is_date() ) { 726 if ( is_year() ) { 727 if ( is_month() ) 728 $title = is_day() ? get_the_date() : trim( single_month_title( ' ', false ) ); 729 else 730 $title = get_query_var( 'year' ); 731 } elseif ( is_month() && !is_day() ) { 732 $title = single_month_title( '', false ); 733 } 734 $view = array( 'date-archive', 'archive' ); 735 } 736 // Search Results 737 elseif ( is_search() ) { 738 $title = strip_tags( get_query_var('s') ); 739 $view = 'search'; 740 } 741 // Page Not Found 742 elseif ( is_404() ) { 743 $view = '404'; 744 } 745 746 // If a view is set, loop through the views to find the relevant title and 747 // title format. 748 if ( !empty( $view ) ) { 749 foreach ( (array) $view as $cur_view ) { 750 if ( empty( $title_format ) && isset( $options["title_format-$cur_view"] ) ) 751 $title_format = $options["title_format-$cur_view"]; 752 if ( empty( $options_title ) && isset( $options["title-$cur_view"] ) ) 753 $options_title = $options["title-$cur_view"]; 754 } 755 } 756 757 // Set the default value if a match was not found. 758 if ( empty( $title_format ) ) 759 $title_format = $options['title_format']; 760 if ( empty( $options_title ) ) 761 $options_title = $options['title']; 762 763 // If the title from the options contains a printf variable, replace it with 764 // the title generated above and use the result as the new title. 765 $use_options_title = false; 766 if ( ! is_array( $options_title ) ) 767 $options_title = array( $options_title ); 768 foreach ( $options_title as $index => $options_title_part ) { 769 if ( false !== strpos( $options_title_part, '%1$s' ) ) { 770 $options_title[$index] = sprintf( $options_title_part, $title ); 771 $use_options_title = true; 772 } 773 } 774 if ( $use_options_title ) 775 $title = $options_title; 776 777 // Flip the title and title format if the direction is rtl. 778 if ( 'rtl' == $options['direction'] ) { 779 if ( is_array($title) ) 780 $title = array_reverse( $title ); 781 if ( is_array($title_format) ) 782 $title_format = array_reverse( $title_format ); 783 } 784 785 // Loop through the title parts stored in the title format array. For each 786 // title part, replace any found variables with their relevant value. If any 787 // title part is empty, skip it to prevent duplicate seperators in the final 788 // title. 789 $new_title_format = array(); 790 foreach ( (array) $title_format as $title_part ) { 791 foreach ( $options['variables'] as $var => $val ) 792 $title_part = str_replace( "%%$var%%", $val, $title_part ); 793 if ( !empty( $title_part ) ) 794 $new_title_format[] = $title_part; 795 } 796 797 // Merge the title format array with the seperator seperating each title 798 // part. 799 $title_format = implode( $options['sep'], $new_title_format ); 800 801 // If the title is an array, merge the parts with the seperator seperating 802 // each part. This allows for complex multi-part view-specific titles. 803 if ( is_array($title) ) 804 $title = implode( $options['sep'], $title ); 805 806 // Construct the finished title by replacing the %%TITLE%% placeholder 807 // variable with the view-specific title. 808 $title = str_replace( '%%TITLE%%', $title, $title_format ); 809 810 echo "<title>" . $title . "</title>\n"; 811 } 812 813 /** 620 814 * Display or retrieve page title for post. 621 815 * 622 816 * This is optimized for single.php template file for displaying the post title. -
wp-includes/theme.php
1328 1328 define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); 1329 1329 1330 1330 break; 1331 1332 case 'title-tag' : 1333 if ( ! is_array( $args ) ) 1334 $args = array( 0 => array() ); 1335 1336 $jit = isset( $args[0]['__jit'] ); 1337 unset( $args[0]['__jit'] ); 1338 1339 // Merge in data from previous add_theme_support() calls. The first value registered wins. 1340 if ( isset( $_wp_theme_features['title-tag'] ) ) { 1341 // It is annoying that array_merge_recursive can't work here to allow for new sub-array entries 1342 // to replace existing ones rather than create an array structure. It would be nice if the 1343 // wp_parse_args function could handle such nested arrays. 1344 if ( isset( $_wp_theme_features['title-tag'][0]['variables'] ) && isset( $args[0]['variables'] ) ) 1345 $title_tag_variables = array_merge( $args[0]['variables'], $_wp_theme_features['title-tag'][0]['variables'] ); 1346 $args[0] = wp_parse_args( $_wp_theme_features['title-tag'][0], $args[0] ); 1347 if ( isset( $title_tag_variables ) ) 1348 $args[0]['variables'] = $title_tag_variables; 1349 } 1350 1351 if ( $jit ) { 1352 $defaults = array( 1353 'sep' => ' - ', 1354 'direction' => 'auto', // auto, rtl, ltr 1355 // %%TITLE%% is a special variable but can still be overridden if desired. 1356 'title_format' => array( '%%TITLE%%', '%%PAGING%%', '%%BLOGNAME%%' ), 1357 'title_format-home' => array( '%%BLOGNAME%%', '%%PAGING%%', '%%DESCRIPTION%%' ), 1358 'title' => '', 1359 'title-archive' => __( 'Archive' ), 1360 /* translators: 1: author name */ 1361 'title-author-archive' => __( 'Author Archive for %1$s' ), 1362 /* translators: 1: date description */ 1363 'title-date-archive' => __( 'Archive for %1$s' ), 1364 /* translators: 1: post type archive title */ 1365 'title-post-type-archive' => __( 'Archive for %1$s' ), 1366 /* translators: 1: search phrase */ 1367 'title-search' => __( 'Search Results for "%1$s"' ), 1368 /* translators: 1: taxonomy name */ 1369 'title-taxonomy-archive' => __( 'Archive for %1$s' ), 1370 'title-404' => __( 'Page not found' ), 1371 'variables' => array( 1372 /* translators: 1: page number */ 1373 'PAGING' => __( 'Page %1$d' ), 1374 'BLOGNAME' => get_bloginfo( 'name' ), 1375 'DESCRIPTION' => get_bloginfo( 'description' ), 1376 ), 1377 ); 1378 1379 if ( isset( $args[0]['variables'] ) ) 1380 $title_tag_variables = array_merge( $args[0]['variables'], $defaults['variables'] ); 1381 $args[0] = wp_parse_args( $args[0], $defaults ); 1382 if ( isset( $title_tag_variables ) ) 1383 $args[0]['variables'] = $title_tag_variables; 1384 } 1385 1386 break; 1387 1331 1388 } 1332 1389 1333 1390 $_wp_theme_features[ $feature ] = $args; 1334 1391 } 1335 1392 1336 1393 /** 1337 * Registers the internal custom header and backgroundroutines.1394 * Registers the internal theme feature routines. 1338 1395 * 1339 1396 * @since 3.4.0 1340 1397 * @access private 1341 1398 */ 1342 function _custom_ header_background_just_in_time() {1343 global $custom_image_header, $custom_background ;1399 function _custom_theme_features_just_in_time() { 1400 global $custom_image_header, $custom_background, $title_tag; 1344 1401 1345 1402 if ( current_theme_supports( 'custom-header' ) ) { 1346 1403 // In case any constants were defined after an add_custom_image_header() call, re-run. … … 1368 1425 $custom_background = new Custom_Background( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); 1369 1426 } 1370 1427 } 1428 1429 if ( current_theme_supports( 'title-tag' ) ) { 1430 add_theme_support( 'title-tag', array( '__jit' => true ) ); 1431 1432 add_action( 'wp_head', '_wp_render_title_tag', 0, 0 ); 1433 } 1371 1434 } 1372 add_action( 'wp_loaded', '_custom_ header_background_just_in_time' );1435 add_action( 'wp_loaded', '_custom_theme_features_just_in_time' ); 1373 1436 1374 1437 /** 1375 1438 * Gets the theme support arguments passed when registering that support