How To Add A Filter To The Homepage H1

by Matt on April 22, 2010

In a recent job I was doing, I needed to change the <h1> tag on the homepage of my client’s site. In Thesis, the homepage <h1> is set as the tagline, and I not only needed to change that, but have a simple solution for all my sites from here on out.

My setup was as follows: I had a static homepage that I had done a bunch of custom work on.

Editing Core Files

Go to the thesis_1x folder. Click on lib then functions, then open document.php.

  • Go to line 95, which says the following:
    echo "\t\t<h1 id=\"tagline\">" . get_bloginfo('description') . "</h1>\n";
    else
    echo "\t\t<p id=\"tagline\">" . get_bloginfo('description') . "</p>\n";
    
  • Replace lines 95-97 with this:
    echo "\t\t<h1 id=\"tagline\">" . apply_filters('homepage_h1', get_bloginfo('description')) . "</h1>\n";
    else
    echo "\t\t<p id=\"tagline\">" . apply_filters('homepage_h1', get_bloginfo('description')) . "</p>\n";
    

Using the H1 Filter

To make use of this new filter, simply add the following to custom_functions.php:

function h1_replace() {
return "New H1 Text Goes Here";
}
add_filter('homepage_h1','h1_replace');

Be sure to change the text to what you want the new H1 to be.

Thesis is just that easy! :D

{ 1 trackback }

{ 12 comments… read them below or add one }

Danny April 22, 2010 at 12:40 am

Not sure I see the point in this… Why not remove thesis_default_header from thesis_hook_header and hook in your own?

Thesis core edits should be kept to things that can’t be done any other way, IMO anyway.

Reply

Matt April 22, 2010 at 8:35 am

Yes, I could use if (is_home() || is_front_page()), but that is a little bit more code. I think that it is perfectly reasonable to want to control the <h1> on the home page without having to rebuild the entire #header, so I added this filter :D

Reply

Danny April 22, 2010 at 10:35 am

It’s perfectly reasonable but “rebuilding the entire #header” is essentially just a copy/paste of the function. I suppose it’s a matter of preference but seeing as most people are not developers and wont note down all of their core edits it’s likely they will loose the functionality with the next Thesis update.

Anyway, here’s the code for those who want the above without the core edit:
http://pastebin.com/RnEYeqZi

Reply

Nicklas Larenholtz June 15, 2010 at 6:12 am

I use a custom content box wich i design css, and place it in the header. And in the settings I take away blogtitle and tagline. You can herein create a very seo friendly man page with H1 tagg subject with contenet beneth it.

Reply

Mike July 1, 2010 at 10:40 am

Awesome!!

But is there anyway to do this while still keeping the normal tagline in the header?

I noticed that my header tagline changed to what I wanted the h1 tag to be?

Reply

Matt July 3, 2010 at 12:09 am

Thesis serves the <h1> as the tagline on the homepage and the title on inner pages. That is the issue ;)

Reply

Mike July 5, 2010 at 10:04 am

Thanks for responding.

I’d just like to keep something that looks like a tagline in my header as it seems to help with conversions.

Reply

kimosabi June 16, 2011 at 8:14 am

Hi Matt,

I’ve tried looking in the document.php file and couldn’t find anywhere that says what you have mentioned on top.

echo “\t\t” . get_bloginfo(‘description’) . “\n”;
else
echo “\t\t” . get_bloginfo(‘description’) . “\n”;

any other ways to get rid of the H1 tag ? or should I leave it there for SEO purpose ?

Reply

goseethem July 10, 2011 at 7:51 am

Thanks for writing this, I will use this on some of my sites.

Reply

Deepanshu August 17, 2011 at 11:41 pm

ooh u just saved me from using 2 h1 tags on homepage..i m new to thesis..thesis is very different from all the other themes i have used ..too many features :roll:

Reply

Flemin September 1, 2011 at 10:47 pm

I tried looking for what you say but couldn’t find it. What I can find is the code below. Appreciate if you could tell me what to change in this case based on the code given below. Thank you.

<?php
}
}
}

Reply

Dan September 26, 2011 at 6:42 am

Danny, Matt, this is interesting.

I would like to be able to change the h1 tag wrapped to the header image on a per page basis, is it possible?
Preferrably without changing the code edits? and also without a if/then statement, but instead ideally be able to set it on the go when creating a new page/post? (have a custom field there where I can assign the h1 tag to whatever I want?). Sorry I am not a pure developer so maybe I am talking complete rubbish…. excuse me for that. But can you tell me if what I am looking for is possible? Thanks !

Reply

Leave a Comment

Previous post:

Next post: