How to Change H2 tags to H1 tags in the Article’s Title in Joomla

We all know that from a search engine perspective, words surrounded by the H1 tags are the ultimate keywords. Apparently, those who developed Joomla do not know this (yes – we are criticizing them!). That’s why they have elected to surround the titles of the articles with H2 tags, making them less important and diluting their importance from a search engine perspective. This is a problem that has negative effects on the search engine rankings of any Joomla website. (By the way, the problem still exists even in the latest version of Joomla).

What’s even more annoying is that Joomla does not easily allow you to change these tags from H2 to H1 through an interface – in fact, the H2 tags are hard coded in the file /components/com_content/views/article/tmpl/default.php!

There are three ways to address this problem:

  1. Change a core Joomla file: This is the quick and dirty fix. All you need to do is to change the <h2> and </h2> tags in the lines 36 and 43 of the file /components/com_content/views/article/tmpl/default.php to <h1> and </h1> respectively. The problem with this method is that you will be changing a core Joomla file – which means that your change can be completely wiped out by a later upgrade in Joomla. A change in core can also potentially lead to a completely inoperable website when future upgrades/updates are applied (although it is very unlikely that this small change can do that).
  2. Create a plugin that will transform H2 tags to H1: This is much more complicated than the above step but you won’t be changing any core file. All you need to do is create a Joomla System plugin that only works on the frontend and that has the following code at heart:

    	function onAfterRender()
    	{
    		$app = &JFactory::getApplication();
    		if($app->isAdmin() || JDEBUG) {
    			return;
    		}
    		$body = JResponse::getBody();
    		str_replace('h2>', 'h1>', $body);
    		JResponse::setBody($body);
    	}
    

    The problem with the above method, however, is that you won’t be able to use h2 tags anymore anywhere – which makes it less than ideal. Another problem is that you will be using a plugin, thus creating extra overhead on the rendering of the page.

  3. Override the default article template: This is the best way of addressing the problem. All you need to do is the following:

    • Copy the file /components/com_content/views/article/tmpl/default.php to /templates/your_template_name/html/com_content/article/default.php
    • Change the H2 tags to H1 tags (in both lines 36 and 43) in /templates/your_template_name/html/com_content/article/default.php
    • That’s it!

    The above method is called overriding, and Joomla accommodates it automatically. Once you do the above, Joomla will use the default.php file located under /templates/your_template_name/html/com_content/article/ to display your articles (which means that it will use the H1 tags to surround the titles). The best thing about this method is that it doesn’t touch the core which makes it future proof. It is also the standard way for overriding default Joomla’s output. (By the way, this method is used by the designers to create new templates)

If you need help doing the above, then why don’t you contact us? We are friendly, we are fast, we are efficient, and our rates are very competitive!

9 Responses to “How to Change H2 tags to H1 tags in the Article’s Title in Joomla”
  1. Comment by Rok — July 9, 2013 @ 9:30 am

    Is there a way to simply turn off the article title (so I can put my H1 directly in the article HTML)?

  2. Comment by Fadi — July 9, 2013 @ 9:40 am

    Hi Rok,

    Yes it’s possible – you can hide the title in the settings of that particular article or globally for all articles. You should also do this at the menu item level if your article is linked from a menu item.

    Please note that it’s not a good practice to set the article title and style it in the content itself – this may create some issues at a later stage.

  3. Comment by Michael — January 2, 2014 @ 10:51 am

    Hi,

    Do you need to replace /components/com_content/views/article/tmpl/default.php with /templates/your_template_name/html/com_content/article/default.php or Just Copy and have the two in one place.

  4. Comment by Fadi — January 2, 2014 @ 12:16 pm

    Hi Michael,

    If you already have a default.php file in the the /templates/your_template_name/html/com_content/article/ folder, then your article’s display template is already overridden. Just make the necessary replacements from H2 to H1 in that file and you should be OK.

  5. Comment by Louise — April 13, 2015 @ 5:19 am

    I want to change the h2 to h1 in my FEATURED article… I’ve managed to change all the other article titles as per your instructions, but my homepage still has the h2 title?

  6. Comment by Fadi — April 14, 2015 @ 6:01 pm

    Hi Louise,

    You will need to override the template for the components/com_content/views/featured/default_item.php file – there’s an <h2> tag there, you will need to change it to <h1>.

  7. Comment by Brian — December 9, 2015 @ 2:02 am

    I had the same problem as Louise, with the H2’s on all pages being updated to H1’s, except the featured article. Problem is there is no default_item.php in the views/featured folder. Help?

  8. Comment by Fadi — December 23, 2015 @ 3:24 am

    Hi Brian,

    Which version of Joomla are you using? Versions from 1.7 and up (including 2.5 and 3.x) have the components/com_content/views/featured/views/tmpl/default_item.php file. If that file structure doesn’t exist under your template’s html folder, then you will need to copy it from the component (e.g you will have under your templates/[your-joomla-template]/html folder the following file: components/com_content/views/featured/views/tmpl/default_item.php).

  9. Comment by Gajanan Naik — September 8, 2016 @ 4:46 am

    Worked like a charm. Thanks a lot!

Leave a comment