-
-
Save tommcfarlin/958b57e0b7c78e9ff13e to your computer and use it in GitHub Desktop.
[WordPress] How to correctly filter wp_title for a customized format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title><?php wp_title( '|', true, 'right' ); ?></title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Provides a standard format for the page title depending on the view. This is | |
* filtered so that plugins can provide alternative title formats. | |
* | |
* @param string $title Default title text for current view. | |
* @param string $sep Optional separator. | |
* @return string The filtered title. | |
* @package mayer | |
* @subpackage includes | |
* @version 1.0.0 | |
* @since 1.0.0 | |
*/ | |
function mayer_wp_title( $title, $sep ) { | |
global $paged, $page; | |
if ( is_feed() ) { | |
return $title; | |
} // end if | |
// Add the site name. | |
$title .= get_bloginfo( 'name' ); | |
// Add the site description for the home/front page. | |
$site_description = get_bloginfo( 'description', 'display' ); | |
if ( $site_description && ( is_home() || is_front_page() ) ) { | |
$title = "$title $sep $site_description"; | |
} // end if | |
// Add a page number if necessary. | |
if ( $paged >= 2 || $page >= 2 ) { | |
$title = sprintf( __( 'Page %s', 'mayer' ), max( $paged, $page ) ) . " $sep $title"; | |
} // end if | |
return $title; | |
} // end mayer_wp_title | |
add_filter( 'wp_title', 'mayer_wp_title', 10, 2 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title><?php bloginfo('name'); ?> | <?php is_home() ? bloginfo('description') : wp_title( '' ); ?></title> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment