Making WordPress.org

Changeset 6969


Ignore:
Timestamp:
03/29/2018 09:38:16 AM (7 years ago)
Author:
ocean90
Message:

Main: About: Use Open Graph data for overriding page titles.

Ensures that document titles are translated as well.

See #3046.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/inc/page-meta-descriptions.php

    r6947 r6969  
    11<?php
    22/**
    3  * Custom template tags
     3 * Custom meta descriptions.
    44 *
    55 * @package WordPressdotorg\MainTheme
     
    1111 * Add custom open-grapgh tags for page templates where the content is hard-coded.
    1212 *
    13  * This is also defined here to allow it to be used on pages where the page template is not included for that page, sych as the embed template.
     13 * This is also defined here to allow it to be used on pages where the page template is not included for that page, such as the embed template.
     14 *
     15 * @param array       $tags Optional. Open Graph tags.
     16 * @param WP_Post|int $post Optional. Post object or ID.
     17 * @return array Filtered Open Graph tags.
    1418 */
    15 function custom_open_graph_tags( $tags = array() ) {
    16     $post = get_post();
     19function custom_open_graph_tags( $tags = [], $post = null ) {
     20    $post = get_post( $post );
     21    if ( ! $post || 'page' !== $post->post_type ) {
     22        return $tags;
     23    }
    1724
    1825    switch ( $post->page_template ) {
     
    108115}
    109116add_filter( 'jetpack_open_graph_tags', __NAMESPACE__ . '\custom_open_graph_tags' );
     117
     118/**
     119 * Maps page titles to Open Graph data which are translatable strings.
     120 *
     121 * @param string      $title The post title.
     122 * @param WP_Post|int $post  Optional. Post object or ID.
     123 * @return string Filtered post tile.
     124 */
     125function custom_page_title( $title, $post = null ) {
     126    if ( ! $post ) {
     127        return $title;
     128    }
     129
     130    $tags = custom_open_graph_tags( [], $post );
     131    return $tags['og:title'] ?? $title;
     132}
     133add_filter( 'the_title', __NAMESPACE__ . '\custom_page_title', 10, 2 );
     134add_filter( 'single_post_title', __NAMESPACE__ . '\custom_page_title', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.