Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created January 15, 2014 12:40
Show Gist options
  • Save tommcfarlin/958b57e0b7c78e9ff13e to your computer and use it in GitHub Desktop.
Save tommcfarlin/958b57e0b7c78e9ff13e to your computer and use it in GitHub Desktop.
[WordPress] How to correctly filter wp_title for a customized format.
<title><?php wp_title( '|', true, 'right' ); ?></title>
<?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 );
<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