How to Create a Custom Joomla 404 Page With SP Page Builder - JoomShaper

How to Create a Custom Joomla 404 Page With SP Page Builder

04 September 2020
Hits 704
6 min read
How to Create a Custom Joomla 404 Page With SP Page Builder

So, let’s say you have built a website and done possibly everything to drive traffic to your site. From adding incredible content to doing SEO, you have implemented every tip and trick to grow your traffic. But what about a custom 404 page? Did you miss out on that?

When it comes to growing your business online, every visitor is important. And when you don’t set up your own customized 404 page, chances are you lose a sale every time a visitor stumbles upon a 404 error. We can’t afford to do that, right? In today’s article, we will walk you through a step by step process to customize your own Joomla 404 page using SP Page Builder. Let’s get started!

What is a 404 Error Page

A 404 error page is thrown when visitors try to access a page on your website which does not exist. The HTTP 404 status code indicates the browser was able to communicate with the server but could not find what was requested. This usually happens when the visitors click on a broken link, misspell a URL, etc.

The common reasons why a 404 error message could appear are:

  • The URL or its content is moved without adjusting the internal links accordingly
  • The URL or its content is deleted
  • The URL is typed into the browser incorrectly
  • The server where the website is hosted is facing an issue
  • The entered domain name does not exist anymore

Why You Should Care About Your Joomla 404 Page

While 404 errors can be frustrating, they cannot be ignored. You have no control over a misspelled URL entered on a visitor’s browser or a broken connection. Therefore, our primary goal is to turn this negative experience into a positive one. A custom 404 error page can:

  • Reduce the bounce rate and keep users on your website
  • Keep people engaged with your site and moving through your sales process
  • Leave them with a good feeling after a positive resolution to their 404 problem
  • Maintain consistent branding across your site
  • Attract additional attention for your brand if you do a good enough job

These are enough reasons to care about your Joomla 404 page.

What to Include in Your 404 Page

So, that leaves us with only one question. What to include in our custom 404 page? A good 404 page should have clear navigation. It should show the visitor the path where they wanted to go in the first place. Or, at least provide a link to the Home page. You can also be creative and display some interesting images or interactions to keep the visitors on the loop before being redirected. Landing on a fun, navigable page can be a nice surprise for the lost visitors, no?

How to Track the 404 Errors on Your Joomla Site

If you are using Google Analytics for your Joomla site you can easily track how many 404 errors visitors are encountering. From Google Analytics Pages settings you can change the Primary Dimension to Page Title and search for “page not found” to see a list of the broken URLs that triggered the 404 errors.

You can also set an alert on Google Analytics that will let you know each time your 404 page view increases above a certain threshold. Check this help center article to learn how to set a Custom Alert.

Create Your Custom 404 Page With SP Page Builder

Now, we will design our own custom Joomla 404 page using SP Page Builder. You can simply create a page just like how we normally create pages using SP Page Builder. To do that, go to your Joomla administrator dashboard > SP Page Builder > Pages > New. Give your page a title and then save to start editing from the front-end editor.

SP Page Builder has 50+ addons to add creative and fun designs to your web pages and the 404 page is a great way to show that off. You can add images, videos, search bar, interactive elements, and make this page really interesting. The primary focus of the design process is to make the users understand they are lost but can still navigate to their desired content. That way, they are less likely to bounce and go to your competitor’s site.

Let’s see an example of how to build a custom 404 page using SP Page Builder:

Step 1: Select your desired addon. For this tutorial, we will be using the Image Content addon.

Step 2: Replace the existing image with your custom image or GIF.

Custom Joomla 404 page

Step 3: Edit the Addon title. Here, we have set the title to 404 Page Not Found!

Custom Joomla 404 page

Step 4: Edit the content with some meaningful text. The goal is to help the lost visitors navigate back to their desired page.

Custom Joomla 404 page

Step 5: Lastly, edit the Button Text and the Button Link to take the users back to your homepage.

Custom Joomla 404 page

Assign the Page to a Menu

Once you have designed your 404 page, it is time to assign the page to a menu item to get the URL of our custom 404 page. Simply do the following to get the job done:

Menu Title: Give your menu item a title, we have given it 404.

Menu Item Type: Menu Item Root

Select Page: Select the custom 404 page that you have created earlier. Save the menu. Make the 404 menu item hidden (important).

Custom Joomla 404 page

Here’s why we need to assign the page to a menu - the Link. Copy the link, we will need this in our next step.

Edit the error.php File in Your Template Root Directory

From the template root directory, we need to edit the error.php file. To do that go to your Joomla root directory > templates > shaper_helixultimate > error.php. Please note, for this tutorial we are using our Helix Ultimate template. Select your template and the path accordingly.

Now, add the following code at the beginning of the file.

// custom 404 redirect
$config = JFactory::getConfig();
$sef = $config->get('sef');
$sef_rewrite = $config->get('sef_rewrite');
$sef_suffix = $config->get('sef_suffix');
$redirect_url = JURI::base();
if(!$sef_rewrite) {
	$redirect_url .= 'index.php/';
}
$redirect_url .= '404'; // menu alias
if($sef_suffix) {
	$redirect_url .= '.html';
}
// if sef is turned off
if(!$sef) {
	$redirect_url = 'index.php?option=com_sppagebuilder&view=page&id=10';
}
if (($this->error->getCode()) == '404') {
	header('Location: ' . $redirect_url, true, 301);
	exit;
}
}

Replace

index.php?option=com_sppagebuilder&view=page&id=10

with the URL of the page that you have copied earlier.

Custom Joomla 404 page

Final Outcome

And, you are done! Now, you have your own custom 404 page that has the same header, footer, and navigation link as the rest of your website pages.

Wrapping Up

The default 404 error page does not give the visitors enough information about the reason for the error and how to proceed further. But a custom 404 page can add value to your Joomla site and navigate the lost visitors back to your website. So, what’s the wait? Set up your own custom Joomla 404 error page today and let us know in the comments how it went. Good luck!

Try SP Page Builder for FREE!Get SP Page Builder Pro

Zareen Tasnim

Zareen Tasnim

Technical Content Writer
Zareen is a technical content writer at JoomShaper. She's a tech enthusiast, writer by day, programmer by night, and always a foodie at heart!

Comments (3)

Pavel
Pavel
This comment was minimized by the moderator on the site

This will only work on a visual level for the user. But the page made in this way gives the wrong status code from the server. Which is very bad for SEO.
This is the correct code:
if ($this->error->getCode() == '404') {
header("HTTP/1.0 404 Not Found");
echo file_get_contents(JURI::root().'add-your-404-page-link-here');
exit;
}

Zareen Tasnim
Zareen Tasnim    Pavel
This comment was minimized by the moderator on the site

Hi Pavel, thank you so much for the feedback. Really appreciate the effort! Have a look at the updated code, hopefully you won't face any issue with this one. Good day!

Pavel
Pavel    Zareen Tasnim
This comment was minimized by the moderator on the site

Good job!

There are no comments posted here yet

Sign up for our newsletter

Don’t miss any updates of our new templates and extensions and all the astonishing offers we bring for you.