Skip to content

Commit c6e9316

Browse files
Merge pull request #121 from MITLibraries/lm444
Re-introduce wp_title implementation
2 parents 8b53721 + beb3066 commit c6e9316

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

web/app/themes/mitlib-parent/functions.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,38 @@ function setup_scripts_styles() {
258258
}
259259
add_action( 'wp_enqueue_scripts', 'Mitlib\Parent\setup_scripts_styles' );
260260

261+
/**
262+
* Creates a nicely formatted and more specific title element text
263+
* for output in head of document, based on current view.
264+
*
265+
* @param string $title Default title text for current view.
266+
* @param string $sep Optional separator.
267+
* @return string Filtered title.
268+
*/
269+
function customize_title( $title, $sep ) {
270+
global $paged, $page;
271+
272+
if ( is_feed() ) {
273+
return $title; }
274+
275+
// Add the site name.
276+
$title .= get_bloginfo( 'name' );
277+
278+
// Add the site description for the home/front page.
279+
$site_description = get_bloginfo( 'description', 'display' );
280+
if ( $site_description && ( is_home() || is_front_page() ) ) {
281+
$title = "$title $sep $site_description";
282+
}
283+
284+
// Add a page number if necessary.
285+
if ( $paged >= 2 || $page >= 2 ) {
286+
$title = "$title $sep " . sprintf( 'Page %s', max( $paged, $page ) );
287+
}
288+
289+
return $title;
290+
}
291+
add_filter( 'wp_title', 'Mitlib\Parent\customize_title', 10, 2 );
292+
261293
/**
262294
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
263295
*/

0 commit comments

Comments
 (0)