0

I'm trying to change the Category Blog article titles from H1 to H2.

I've already tried creating a template override for com_content > tmpl > article > default.php. I found this line:

<div class="page-header"> <h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1> </div>

But that is only for the page header, not the article title. The article title is placed by this line:

<<?php echo $htag; ?> itemprop="headline"> <?php echo $this->escape($this->item->title); ?> </<?php echo $htag; ?>>

But there is no tag around that code to control the heading size.

Right now in my site, in the Category Blog menu item settings, under Page Display, "Show Page Heading" is set to Hide. This causes the article titles to be H1 tags. This is a problem because the name of my blog is already the H1 tag on the page. If I Show the page headings instead, the article title becomes a H2 tag like I want, but then an unwanted page heading appears above it, set as a H1 tag.

I can create a CSS hack like this to remove the unwanted page heading, but I wonder if there's a better solution.

div.page-header h1 {display:none}

1 Answer 1

1

It's questionable whether the brand/site name should be in H1. To my knowledge H1 should be used for the main content of a given page. In this case that would be the article title or the custom heading if such exists. So you should considering modifying the template first. But to answer your question, you missed this part:

$htag = $this->params->get('show_page_heading') ? 'h2' : 'h1';

It defines the heading tag later used by the article title, based on whether custom heading is shown or not. In your case you would have to increase the heading by one level:

$htag = $this->params->get('show_page_heading') ? 'h3' : 'h2';
1
  • Thank you. For 90% of the site, the title does reflect the main content of the page. But the title of the blog goes in that same spot, taking up the H1 tag. The article titles therefore must be H2s.
    – Kris Hunt
    Aug 1 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.