How To Create a Custom 404 Error Page in Joomla

How To Create a Custom 404 Error Page in Joomla

Because you can't avoid all the 404 errors on your site, it's always smart to keep your visitors into your pages. To help you to create a custom 404 error page on your website, I've wrote this fast tutorial.

It might be interesting to display a nice 404 error page to keep longer on your website your lost visitors . In few steps and with a 100% Joomla solution, we gonna redirect our lost visitors to a new page, specificly created and totaly integrated to our template. Lets's go!

#1 Create a new menu item

  • Open your admin panel and navigate to Menu, then Main menu and select the sub-menu Add New Menu Item,
  • Adding new menu item Custom 404 Error Page
  • Open the tab Link Type and for the parameter Display in Menu, select NO,
    Hidding menu Custom 404 Error Page
  • Indicate the name of your menu item (for example: 404 error page),
  • For the parameter Menu Item Type, click on the blue button Select and then, click on Articles and on Single article,
    Create an article in Joomla - Custom 404 Error Page

#2 Create the new 404 article

  • Click on Create to create your new article,
  • First, indicate a title for your article (for example: 404 error article),
  • Add your content in the text area and fill all the relevant infos you may need for your article (meta description, author, etc.),
    Adding content in an article in Joomla - Custom 404 Error Page
  • Once you've done, click on the blue button Save & Close in the bottom of the popup,
  • Click on the green button Save on the top left of your page,

Now, Joomla had generated the URL of your article index.php?option=com_content&view=article&id=XX (where XX is the ID of your article). Select and copy it to your clipboard.

Menu item created in Joomla
  • Click on the Save & Close button.

In the list of the menu items, note the ID of your 404 menu item. Copy it.

Menu item ID in Joomla

#3 Edit the template

  • From your admin panel, navigate to Extensions, then Templates and Templates,
    Edit the template in Joomla
  • Click on your template to open it,
  • In the left list, click on error.php to open this file in the editor,
    Edit the error.php file in Joomla
  • Just right after:
    defined('_JEXEC') or die;

    add this code:

    if (($this->error->getCode()) == '404') {
    	header('Location: ' . Jroute::_("index.php?option=com_content&view=article&id=XXItemid=YY", false));
    	exit;
    }

    Check that the XX is the ID of your article and the YY is the ID of your menu item created in the previous step.

    Template editor Joomla
  • Click on the Save & Close button.

Conclusion

Open any page of your website and add any dummy contenu in the URL. Your 404 error page must be displayed now.

For information, a 404 error page is also a good occasion to display something useful, informative, fun or completly offbeat for your visitors.
Don't hesitate to post your custon 404 erro pages in the comments below.

Because you can't avoid all the 404 errors on your site, it's always smart to keep your visitors into your pages. To help you to create a custom 404 error page on your website, I've wrote this fast tutorial.

It might be interesting to display a nice 404 error page to keep longer on your website your lost visitors . In few steps and with a 100% Joomla solution, we gonna redirect our lost visitors to a new page, specificly created and totaly integrated to our template. Lets's go!

#1 Create a new menu item

  • Open your admin panel and navigate to Menu, then Main menu and select the sub-menu Add New Menu Item,
  • Adding new menu item Custom 404 Error Page
  • Open the tab Link Type and for the parameter Display in Menu, select NO,
    Hidding menu Custom 404 Error Page
  • Indicate the name of your menu item (for example: 404 error page),
  • For the parameter Menu Item Type, click on the blue button Select and then, click on Articles and on Single article,
    Create an article in Joomla - Custom 404 Error Page

#2 Create the new 404 article

  • Click on Create to create your new article,
  • First, indicate a title for your article (for example: 404 error article),
  • Add your content in the text area and fill all the relevant infos you may need for your article (meta description, author, etc.),
    Adding content in an article in Joomla - Custom 404 Error Page
  • Once you've done, click on the blue button Save & Close in the bottom of the popup,
  • Click on the green button Save on the top left of your page,

Now, Joomla had generated the URL of your article index.php?option=com_content&view=article&id=XX (where XX is the ID of your article). Select and copy it to your clipboard.

Menu item created in Joomla
  • Click on the Save & Close button.

In the list of the menu items, note the ID of your 404 menu item. Copy it.

Menu item ID in Joomla

#3 Edit the template

  • From your admin panel, navigate to Extensions, then Templates and Templates,
    Edit the template in Joomla
  • Click on your template to open it,
  • In the left list, click on error.php to open this file in the editor,
    Edit the error.php file in Joomla
  • Just right after:
    defined('_JEXEC') or die;

    add this code:

    if (($this->error->getCode()) == '404') {
    	header('Location: ' . Jroute::_("index.php?option=com_content&view=article&id=XXItemid=YY", false));
    	exit;
    }

    Check that the XX is the ID of your article and the YY is the ID of your menu item created in the previous step.

    Template editor Joomla
  • Click on the Save & Close button.

Conclusion

Open any page of your website and add any dummy contenu in the URL. Your 404 error page must be displayed now.

For information, a 404 error page is also a good occasion to display something useful, informative, fun or completly offbeat for your visitors.
Don't hesitate to post your custon 404 erro pages in the comments below.

Enjoyed this post?

Subscribe to the Web-eau.net newsletter to receive monthly information exclusively reserved for subscribers.

You can unsubscribe at any time. Learn more about it within our privacy Policy page.

Daniel Dubois - auteur à web-eau.net

About Daniel

Passionate about the Web since 2007, Daniel defends the widow and the orphan of the Web by creating W3C-compliant sites. With his experience, he shares his knowledge in an open source mindset. Very involved in favor of the Joomla CMS since 2014, he is also a speaker and founder of the Joomla User Group Breizh.

Website Facebook Twitter Joomla E-mail

Related Articles

web-eau.net

29800 Landerneau

+33 674 502 799

daniel@web-eau.net