Making WordPress.org

Changeset 8371


Ignore:
Timestamp:
02/28/2019 07:10:01 AM (5 years ago)
Author:
dd32
Message:

WordPress.TV: Adjust the title formats.

This upgrades the theme to using the newer title support which handles the requested structure better.

Fixes #4209.

Location:
sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/functions.php

    r8367 r8371  
    1919        }
    2020
    21         // Add any actions/filters that should run for WordPress.TV & Blog.WordPress.TV here.
    22         add_action( 'wp_head', array( $this, 'rel_canonical' ) );
    23     }
    24 
    25     /**
    26      * Runs during after_setup_theme.
     21        add_action( 'after_setup_theme', array( $this, 'setup_always' ) );
     22    }
     23
     24    /**
     25     * Runs during after_setup_theme on WordPress.TV
    2726     */
    2827    function setup() {
     
    3938        add_filter( 'pre_option_blog_upload_space', array( $this, 'blog_upload_space' ) );
    4039
     40        add_filter( 'document_title_parts', array( $this, 'document_title_parts' ) );
     41
    4142        register_nav_menus( array(
    4243            'primary'            => __( 'Primary Menu', 'wptv' ),
     
    4445            'featured_wordcamps' => __( 'Featured WordCamps', 'wptv' ),
    4546        ) );
     47    }
     48
     49    /**
     50     * Runs during after_setup_theme on WordPress.TV & blog.WordPress.TV
     51     */
     52    function setup_always() {
     53        add_theme_support( 'title-tag' );
     54
     55        // Add any actions/filters that should run for WordPress.TV & Blog.WordPress.TV here.
     56        add_action( 'wp_head', array( $this, 'rel_canonical' ) );
    4657    }
    4758
     
    7182            printf( '<link rel="canonical" href="%s">', esc_url( $canonical ) );
    7283        }
     84    }
     85
     86    /**
     87     * Filter archive titles where needed.
     88     */
     89    function document_title_parts( $title ) {
     90        $sep = apply_filters( 'document_title_separator', '-' );
     91
     92        if ( is_tax( 'language' ) ) {
     93            $title['title'] = sprintf(
     94                /* translators: %s: The language name. */
     95                __( 'Videos in %s', 'wptv' ),
     96                get_queried_object()->name
     97            );
     98        } elseif ( is_tax() || is_tag() || is_category() ) {
     99            // Suffix the Taxonomy label to the Term Name
     100            $tax = get_taxonomy( get_queried_object()->taxonomy );
     101            $tax_label = $tax->labels->singular_name ?? $tax->label;
     102
     103            $title['title'] .= " $sep $tax_label";
     104        }
     105
     106        return $title;
    73107    }
    74108
     
    824858
    825859/**
    826  * Create a nicely formatted and more specific title element text for output
    827  * in head of document, based on current view.
    828  *
    829  * @global $paged
    830  * @global $page
    831  *
    832  *
    833  * @param string $title Default title text for current view.
    834  * @param string $sep   Optional separator.
    835  * @return string The filtered title.
    836  */
    837 function wptv_wp_title( $title, $sep ) {
    838     if ( is_feed() ) {
    839         return $title;
    840     }
    841 
    842     global $paged, $page;
    843 
    844     // Add the site name.
    845     $title .= get_bloginfo( 'name', 'display' );
    846 
    847     // Add the site description for the home/front page.
    848     $site_description = get_bloginfo( 'description', 'display' );
    849     if ( $site_description && ( is_home() || is_front_page() ) ) {
    850         $title = "$title $sep $site_description";
    851     }
    852 
    853     // Add a page number if necessary.
    854     if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    855         $title = "$title $sep " . sprintf( __( 'Page %s', 'wptv' ), max( $paged, $page ) );
    856     }
    857 
    858     return $title;
    859 }
    860 add_filter( 'wp_title', 'wptv_wp_title', 10, 2 );
    861 
    862 /**
    863860 * Append the slide URL to the excerpt
    864861 *
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/header.php

    r6374 r8371  
    1515<head>
    1616    <meta charset="<?php bloginfo( 'charset' ); ?>">
    17     <title><?php wp_title( '|', true, 'right' ); ?></title>
    1817
    1918    <link rel="alternate" type="application/rss+xml" title="<?php esc_attr_e( 'WordPress.tv RSS Feed', 'wptv' ); ?>" href="https://wordpress.tv/feed/" />
Note: See TracChangeset for help on using the changeset viewer.