Created
July 10, 2012 21:07
-
-
Save thefuxia/3086243 to your computer and use it in GitHub Desktop.
Static front page with page 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 # -*- coding: utf-8 -*- | |
/** | |
* Plugin Name: Static front page with page title | |
* Description: Uses the page title for the front page if a static page is set. | |
* Plugin URI: http://wordpress.stackexchange.com/q/58073/73 | |
* Version: 2012.07.10 | |
* Author: Thomas Scholz | |
* Author URI: http://toscho.de | |
* License: MIT | |
* License URI: http://www.opensource.org/licenses/mit-license.php | |
* | |
* Static front page with page title, Copyright (C) 2012 Thomas Scholz | |
*/ | |
// Hook in very late, let the theme fix it first. | |
add_filter( 'wp_title', 't5_fill_static_front_page_title', 100 ); | |
/** | |
* Fill empty front page title if a static page is set. | |
* | |
* @wp-hook wp_title | |
* @param string $title Existing title | |
* @return string | |
*/ | |
function t5_fill_static_front_page_title( $title ) | |
{ | |
// another filter may have fixed this already. | |
if ( '' !== $title or ! is_page() or ! is_front_page() ) | |
{ | |
return $title; | |
} | |
$page_id = get_option( 'page_on_front' ); | |
$page = get_page( $page_id ); | |
if ( ! $page or '' === $page->post_title ) | |
{ | |
$title = get_option( 'blogname' ); | |
} | |
else | |
{ | |
$title = $page->post_title; | |
} | |
// We don’t know if there is any output after the title, so we cannot just | |
// add the separator. We use an empty space instead. | |
return "$title "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment