WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How does one change the <title> for a date based archive page? (11 posts)

  1. wkor
    Member
    Posted 4 years ago #

    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.

  2. stvwlf
    Member
    Posted 4 years ago #

    Using a plugin like All in One SEO is a simple and flexible way.

  3. wkor
    Member
    Posted 4 years ago #

    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.

  4. esmi
    Forum Moderator
    Posted 4 years ago #

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

  5. wkor
    Member
    Posted 4 years ago #

    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.

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    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.

  7. wkor
    Member
    Posted 4 years ago #

    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?

  8. wkor
    Member
    Posted 4 years ago #

    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)?

  9. stvwlf
    Member
    Posted 4 years ago #

    Post the relevant code from header.php

  10. wkor
    Member
    Posted 4 years ago #

    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.

  11. wkor
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags