WordPress.org

Making WordPress.org

Changeset 7360


Ignore:
Timestamp:
07/02/2018 11:54:43 PM (2 years ago)
Author:
obenland
Message:

Main: Make child header work for any child page

...and not just for child pages of the About page.

See #3673.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/functions.php

    r7359 r7360  
    193193
    194194/**
     195 * Customizes the parent page title when rendering as a site title on child pages.
     196 *
     197 * Example: 'About' on all child pages of the About page.
     198 *
     199 * @param string $title   Post Title.
     200 * @param int    $post_id Post ID.
     201 * @return string
     202 */
     203function parent_page_title( $title, $post_id ) {
     204    $title_post = get_post( $post_id );
     205    if ( 'about' === $title_post->post_name && get_post()->post_name !== $title_post->post_name ) {
     206        $title = esc_html_x( 'About', 'Page title', 'wporg' );
     207    }
     208
     209    return $title;
     210}
     211add_filter( 'the_title', __NAMESPACE__ . '\parent_page_title', 11, 2 );
     212
     213/**
    195214 * Custom template tags.
    196215 */
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/header-child-page.php

    r7350 r7360  
    2222        <header id="masthead" class="site-header col-12" role="banner">
    2323            <div class="site-branding">
    24                 <p class="site-title"><a href="<?php echo esc_url( home_url( '/about/' ) ); ?>" rel="bookmark"><?php echo esc_html_x( 'About', 'Page title', 'wporg' ); ?></a></p>
     24                <p class="site-title"><a href="<?php echo esc_url( get_permalink( get_post()->post_parent ) ); ?>" rel="bookmark"><?php echo get_the_title( get_post()->post_parent ); ?></a></p>
    2525
    2626                <nav id="site-navigation" class="main-navigation" role="navigation">
Note: See TracChangeset for help on using the changeset viewer.