• Resolved wkor

    (@wkor)


    Working in header.php, how would one change what is displayed in the <title> element for date based archive pages? Right now I have ‘Blog Name: 2009 October’ and I’m not down with that.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Using a plugin like All in One SEO is a simple and flexible way.

    Thread Starter wkor

    (@wkor)

    Alright. Are there any less simple and flexible ways? I just want to fix it and I’m willing to get my hands dirty; don’t really want to install A-I-O-SEO just for that.

    What sort of text do you want in the <title>?

    Thread Starter wkor

    (@wkor)

    Well, like I said, I have ‘Blog Name: 2009 October’. I’d rather have ‘Blog Name October 2009’. Best of all would be to know what function or whatnot I’m supposed to be messing with to change the thing.

    Try adding:

    function theme_get_archive_date() {
    	if (is_day()) $this_archive = get_the_time('j F Y');
    	elseif (is_month()) $this_archive = get_the_time('F Y');
    	else $this_archive = get_the_time('Y');
    	return $this_archive;
    }

    to your theme’s functions.php file. Then amend the <title> in header.php to use something like:

    <title><?php if(is_search()) {echo ' Search Results for ''.wp_specialchars($s,1).'' on ';bloginfo('name');}
    elseif (is_category() || is_author()) {wp_title(':',true,'right');bloginfo('name');}
    elseif(is_tag()) { echo 'Entries tagged with ';wp_title('',true);if(wp_title('',false)) {echo ' : ';}	bloginfo('name');}
    elseif(is_archive() && function_exists('theme_get_archive_date')) {echo theme_get_archive_date().' : ';bloginfo('name');}
    elseif(is_404()) {bloginfo('name');echo 'Page not found!';}
    elseif (have_posts()) {wp_title(':',true,'right');bloginfo('name');}
    else {bloginfo('name');}?>
    </title>

    Advance apologies for any syntax errors in that last block. Just grabbed it and trimmed it down from one of my themes.

    Thread Starter wkor

    (@wkor)

    Ah, many thanks. I’ll test it out and report back. So get_the_time will work for getting the info of a date based archive page?

    Thread Starter wkor

    (@wkor)

    Alright, I applied some of your code, but unfortunately I’m ending up with double titles, like this: Blog Name: October 2009 2009 October. Do you know how I can override the default title (2009 October)?

    Post the relevant code from header.php

    Thread Starter wkor

    (@wkor)

    Sorry, I should have done that. Here ’tis.

    <title><?php bloginfo('name'); ?>
    <?php
    if (is_home()) {}
    elseif(is_archive() && function_exists('theme_get_archive_date'))
    {echo ': ', theme_get_archive_date();}
    else {
    echo ":"; } ?>
    <?php wp_title('');?></title>

    References esmi’s function theme_get_archive_date.

    Thread Starter wkor

    (@wkor)

    Shame on me for not catching it earlier. That means: I found the problem. It was that <?php wp_title('');?> bit. It wasn’t in the control structure, so I fixed that. Current code is:

    <title><?php bloginfo('name'); ?>
    <?php
    if (is_home()) {}
    elseif(is_archive() && function_exists('theme_get_archive_date'))
    {echo ': ', theme_get_archive_date();}
    else {
    echo ":";
    wp_title('');
    } ?>
    </title>

    Thanks much in any case.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How does one change the <title> for a date based archive page?’ is closed to new replies.