Changeset 6969
- Timestamp:
- 03/29/2018 09:38:16 AM (7 years ago)
- 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 1 1 <?php 2 2 /** 3 * Custom template tags3 * Custom meta descriptions. 4 4 * 5 5 * @package WordPressdotorg\MainTheme … … 11 11 * Add custom open-grapgh tags for page templates where the content is hard-coded. 12 12 * 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. 14 18 */ 15 function custom_open_graph_tags( $tags = array() ) { 16 $post = get_post(); 19 function custom_open_graph_tags( $tags = [], $post = null ) { 20 $post = get_post( $post ); 21 if ( ! $post || 'page' !== $post->post_type ) { 22 return $tags; 23 } 17 24 18 25 switch ( $post->page_template ) { … … 108 115 } 109 116 add_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 */ 125 function 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 } 133 add_filter( 'the_title', __NAMESPACE__ . '\custom_page_title', 10, 2 ); 134 add_filter( 'single_post_title', __NAMESPACE__ . '\custom_page_title', 10, 2 );
Note: See TracChangeset
for help on using the changeset viewer.