I post at SearchCommander.com now, and this post was published 16 years 1 day ago. This industry changes FAST, so blindly following the advice here *may not* be a good idea! If you're at all unsure, feel free to hit me up on Twitter and ask.
We use WordPress to build a lot of websites, not only because it’s so easy, but because it’s great for search engine optimization.
However, when I began using it to build full sites as opposed to just supplementing existing sites with blogs, I noticed a big shortcoming.
If you create your static pages, then whatever you name the page becomes the menu item, as well as the headline at the top of the page. Therefore, on the homepage we would be stuck with a headline that said “Home” rather than an appropriate and relevant phrase.
Also, for some reason, 99 out of 100 WordPress themes (including Kubrick) don’t include an H1 tag up there, but instead are defaulted to H2 tags.
That made it not only ugly for visitors, but also not well optimized for the search engines, since I firmly still believe that webpages need headlines.
Calling this solution “mine” might not be fair, since all I did was identify the problem… It was my programmer Heather that solved it by coming up with the following solution.
As a bonus, it not only solved the default H2 problem, but it gave us an instant answer for having the menu say one thing, while the page says another aa the headline.
How to Change the H1 Tag
In your theme’s page.php and single.php files, look whatever is inside your H2 tags. Just replace whatever is between them with the following code:
<h1><?php $thisPost = $post -> ID; if (get_post_meta($thisPost, changeH1, true) != ”) {
echo (get_post_meta($thisPost, changeH1, true));
} else {
the_title();
}
?>
</h1>
Instantly, your H2 tag is gone from your pages and posts, replaced by an H1 that matches the subject of the post or the name of the page. Bingo, bango bongo, done.
*note that in some cases, the theme’s style.css file will treat these differently, making the font too large for your taste. If that happens, just change it in the style sheet.
Now is where it gets REALLY good….
Suddenly, we have the ability to edit each H1 tag as we see fit. If we do nothing, then it will still just match what we’ve written in the subject of the post or used as the name of the page, but we enter a bit of “Custom field” information, we can make it say whatever we want.
Be sure to use “changeH1” (with a lowercase c and an uppercase H) just like you placed in the code above, and then put the headline you want in the value area.
After you use it the first time, you’ll never have to remember it again either, because it will be available from the pulldown menu, so all you have to do is select it and write the headline that you want to use as the H1 tag on the page.
To see a similar modification, look no further than the top of this page, where you can see that my H tag is different than the page title, nut I’ve also left in the behavior that makes the H1 a link – in this case, to itself.
Again, I have to thank my programmer Heather Barger, and if this all seems too complex, she’s laid it out nicely here with step by step WordPress H1 hack instructions.
Why am I giving away this secret now?
Well first, after using it for nearly two years, I doubt it’s much of a secret anymore,Β and although I’ve still not read it elsewhere, I keep expecting to. If you have a link t osomeone else that’s posted it previously, please leave it as a comment here.
Second, because I’ve had this post in my drafts for almnost a year, and I already redi the screen shots once. Now with Wprdpress 2.7 out, I’m not doing them again, so I figured it was time to post it. !
Third, and more importantly,Β I’m still trying to work on improving my Karma after my fiasco with Peak Studios from earlier in the month.Β Maybe I can somehow overshadow the embarrassment of that voicemail I left…
Finally, because it’s the holidays, and I’m in the spirit of giving.
I’d like to wish all of you a Merry Christmas, Happy Hanukkah, a Joyus Kwanza, or just a gool old fashioned Happy New Year… Choose whatever least offends you.
Scott,
What are the advantages to using the php code listed and the changeH1 tag as opposed to just installing the WordPress plugin all in one seo?
The All in one SEO plugin is great, but it doesn’t anything to change your themes H2 tag into an H1.
The importance of that might be debatable by some, but not to me. I want a headline.
However, far cooler and more important when doing site development in WP, this hack allows you to have the menu say one thing and the page say another.
Good tips for furthering SEO..I know I use wordpress on some other sites I have had in the past
Hi Many thanks followed the download link from www. mywebtronics.com and tried the plugin but didn’t see the code to be changed, so it threw up an error. Will try again now cheers.
EXACTLY what I was looking for Scott, THANK YOU!!!
Kudos for sharing this trick!
No, it did work for me. I made the code substitution and did not work.
The H2 has disapeared and the H1 is the same, wrapping the blog name and not the post title.
Please advise if you can.
I will try it with my photo blog. π
I’m In the same boat as Riccardo!!! Am i missing something? please help!!
If Ricardo and you both have it “wrapping the blog name” then that’s because there’s an H1 hard coded into your theme – Lots of theme designers do this in a misguided attempt to “add an H1 tag for SEO” – You should have your theme edited to remove that H1…
hey Scott! thanks for the prompt reply, true to form my theme is a professional theme and i checked the page.php and single.php and saw all the h1 tags scattered everywhere? but a scan of the site still indicates that the h1 tags are missing :(. what exactly am i supposed to change really?
Great hack…I also do it to some of my sites,but they are not cms based websites and the flexibility is enormous!!
I dont understand this post, this about plugin or php code…
It’s about .php code…
Interesting read , but i’m a tad stuck with the h1 tags been scattered on the page.