[wp-trac] [WordPress Trac] #12542: Fix title and h1 elements for Twenty Ten theme
WordPress Trac
wp-trac at lists.automattic.com
Mon Mar 29 04:51:13 UTC 2010
#12542: Fix title and h1 elements for Twenty Ten theme
--------------------------+-------------------------------------------------
Reporter: mikeschinkel | Owner: iammattthomas
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 3.0
Component: Themes | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch |
--------------------------+-------------------------------------------------
Comment(by mikeschinkel):
Replying to [comment:11 jane]:
> @mikeschinkel: Why can't people just use a plugin that drops a simple
postbox on the page editor with a checkbox for "Hide page title" or
something?
The problem is that the theme hardcodes the control of this so a plugin
cannot do this. That is why I was suggesting what I suggested.
''Another option'' would be to (start) add(ing) some filters designed to
be used by themes. For example, instead of this on lines ~5-8 in
{{{twentyten/header.php}}}:
{{{
<title><?php
if ( is_single() ) {
single_post_title(); echo ' | '; bloginfo( 'name' );
} elseif ( is_home() || is_front_page() ) {
bloginfo( 'name' ); echo ' | '; bloginfo( 'description' );
twentyten_the_page_number();
}}}
We could add a filter called "{{{theme_head_site_title}}}" which would be
called in the theme like so:
{{{
<title><?php
if ( $head_title = apply_filter('theme_head_site_title',false) ) {
echo $head_title;
} elseif ( is_single() ) {
single_post_title(); echo ' | '; bloginfo( 'name' );
} elseif ( is_home() || is_front_page() ) {
bloginfo( 'name' ); echo ' | '; bloginfo( 'description' );
twentyten_the_page_number();
}}}
Adding that filter would allow me to achieve my goal in my child theme
using this code in functions.php:
{{{
add_filter('theme_head_site_title','my_theme_head_site_title');
function my_theme_head_site_title($title) {
if (is_front_page())
$title = get_bloginfo( 'name' ) . ' | ' . get_bloginfo( 'description'
);
elseif (is_home())
$title = wp_title( ' | ',false ) . ' | ' . get_bloginfo( 'name' ) .
twentyten_get_page_number();
return $title;
}
}}}
Also in {{{twentyten/header.php}}} at line ~33:
{{{
<div id="site-title"><span><a href="<?php echo home_url( '/' ); ?>"
title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?></a></span></div>
}}}
We could add a filter called "{{{theme_branding_site_title}}}" which would
be called in the theme like so:
{{{
<?php echo apply_filters('theme_branding_site_title',
'<div id="site-title"><span><a href="' . home_url( '/' ) .
'" title="' . esc_attr( get_bloginfo( 'name', 'display' ) ) .
'" rel="home">' . bloginfo( 'name' ) . '</a></span></div>'); ?>
}}}
Adding that filter would allow me to achieve my goal in my child theme
using this code in functions.php:
{{{
add_filter('theme_branding_site_title','my_theme_branding_site_title');
function my_theme_branding_site_title($title) {
if (is_front_page()) {
$title = str_replace('<div id="site-title">','<h1 id="site-
title">',$title);
$title = str_replace('</a></span></div>','</a></span></h1>',$title);
}
return $title;
}
}}}
Finally in {{{twentyten/page.php}}} and {{{twentyten/onecolumn-page.php}}}
we could replace the following at lines ~5 and ~15, respectively:
{{{
<h1 class="entry-title"><?php the_title(); ?></h1>
}}}
With this:
{{{
<?php echo apply_filters('theme_page_title',
'<h1 class="entry-title">' . the_title('','',false) . '</h1>'); ?>
}}}
Adding that filter would allow me the last part needed to achieve the goal
in my child theme using this code in functions.php:
{{{
add_filter('theme_page_title','my_theme_page_title');
function my_theme_page_title($title) {
if (is_front_page()) {
$title = '';
}
return $title;
}
}}}
Without this (or something else to address the issue) then:
1.) Themers will have to duplicate header, page, and onecolumn-page to
create a child theme just to address this issue. If twentyten gets bug
fixes or enhancements in those files I don't get them until I discover and
make the same change, and
2.) Themers developing themes will see the pattern in twentyten and
duplicate it, thus ensuring we'll have this same problem with practically
every other theme out there (I quit using several other themes already
because of this issue, Thesis being the main one I otherwise liked because
it outputs an page title on the front page, for example, and fixing it was
too difficult.)
OTOH, with these three (3) simple hooks I just proposed many themers will
recognize the need (even if they don't fully understand it) and many of
them will offer the same hooks.
Replying to [comment:12 nacin]:
> At the moment, I'm tentatively in agreement that the page title for a
static front page should not show up in the template.
Lately, here on your blog and elsewhere, you have been my hero. :)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/12542#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list