Is there an easy way to achieve one H1 per page? [for page title]

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
DocMartin's picture

When starting with Drupal recently, I was a bit startled to see that - in Garland and Aberdeen themes - there were H1 tags around site title. Removed these, easily enough.

But - I'd like to use H1 for main page title, which is surely the intended purpose, and important for SEO - Google, say, figuring that the words in H1 tags are key to describing what a page is about.

I think easy enough to do for node titles. But then, might find that get several h1 tags if have a list of node titles on a page.
So I'm curious: is there an easy way to automatically have one h1 per page, for the main page title?
[Rather than a crude workaround I've used with Joomla: adding a title with H1 tags within body of an article.]

Comments

Yes there is, on your

slayerment's picture

Yes there is, on your page.tpl set do something like
<h1><?php print $title ?></h1>
This will give you 1 unique title for each page displayed in Drupal.

Then for the node teasers where you have multiple listed you can edit your node.tpl to display the node titles as say <h2> or <h3> tags if ($page == 0).

Hope that helps.

thanks!

DocMartin's picture

Thanks! - I'll give this a try.

(It's something that had me flummoxed with Joomla, even tho was sent a hack for a core file - which I tried without success.)

not ideal method?

DocMartin's picture

Finally found the time to look at this.

Having looked at the page.tpl.php file, it seems if I include php code to print title here, then I'll have the title repeated shortly afterwards as well (as title of the first node - on many pages, the only node). This in addition to having the title also used as page title in html head. Not too keen on such repetition.

Instead, I'd hoped to have the first node title appear once only within the page, with h1 tags.

H1

Z2222's picture

Isn't it better to put <h1><?php print $title ?></h1> in node.tpl.php instead of page.tpl.php? If you put it in page.tpl.php I believe you will end up with extra empty H1 elements on some pages (depending on node.tpl.php). Some themes (like Bluemarine) have this problem.

Duplicate H1 elements

Z2222's picture

Actually, I don't think you can remove the <h1> from page.tpl.php, but you could make a conditional statement to only print it if it exists.

Search Engine Optimization (SEO)

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week