A well-designed 404 page is an important part of any professional WordPress website. When visitors land on a URL that no longer exists, the default WordPress or GeneratePress 404 page may not provide enough guidance to keep them on your website.
Fortunately, if you’re using the GeneratePress Premium (GP Premium) theme, you can create a clean and professional custom 404 page using the Elements → Hook feature.
In this guide, you’ll learn how to create a custom GeneratePress 404 page with a clear error message, a home button, and a website search box—without creating a separate page template or editing your theme files.
What Is a 404 Error Page?
A 404 error occurs when a visitor tries to access a URL that doesn’t exist on your website.
This can happen when:
- A page has been deleted.
- A post has been moved.
- A URL has been changed.
- A visitor enters an incorrect URL.
- An old link points to content that no longer exists.
Instead of leaving visitors with a confusing error message, a custom 404 page can explain what happened and provide useful options for continuing their visit.
Why Create a Custom 404 Page?
The 404 page is often overlooked, but it can improve the overall user experience of your website.
A professional 404 page should make it easy for visitors to recover from a broken or incorrect URL.
A good custom 404 page can include:
- A clear “404” error message.
- A short explanation.
- A link back to the homepage.
- A search form.
- A simple, mobile-friendly design.
The goal isn’t to make the page complicated. Instead, the goal is to help visitors find what they’re looking for as quickly as possible.
GeneratePress Custom 404 Page Using a Hook
GeneratePress Premium provides an Elements system that allows you to add custom content to different areas of your website.
For this method, we’ll use a Hook Element and target the WordPress 404 template.
Step 1: Create a Hook Element
From your WordPress dashboard, go to:
Appearance → Elements → Add New Element
Select:
Hook
Give the element a name such as:
Custom 404 Page
Step 2: Select the Hook Location
For this implementation, set the Hook location to:
wp_head
Then configure the display location as:
404 Template
Make sure:
Execute PHP = OFF
This ensures that the code is only loaded when a visitor is viewing a 404 page.
Step 3: Add the Custom 404 Code
The following code creates a simple and professional 404 page with:
- A large 404 number.
- A page-not-found heading.
- A helpful description.
- A “Back to Home” button.
- A website search box.
- Responsive styling for mobile devices.
<style>
body.error404 .site-content .inside-article > * {
display: none !important;
}
body.error404 .site-content .inside-article .custom-404-page {
display: block !important;
}
.custom-404-page {
width: 100%;
padding: 90px 20px 110px;
text-align: center;
}
.custom-404-inner {
width: 100%;
max-width: 760px;
margin: 0 auto;
}
.custom-404-number {
margin-bottom: 15px;
font-size: clamp(80px, 14vw, 140px);
line-height: 0.9;
font-weight: 800;
letter-spacing: -6px;
opacity: 0.12;
}
.custom-404-page h1 {
margin: 0 0 18px;
font-size: clamp(32px, 5vw, 46px);
line-height: 1.2;
font-weight: 700;
}
.custom-404-description {
max-width: 620px;
margin: 0 auto;
font-size: 18px;
line-height: 1.7;
}
.custom-404-actions {
margin-top: 30px;
}
.custom-404-button {
display: inline-block;
padding: 14px 28px;
border-radius: 6px;
background: var(--accent, #1e73be);
color: #fff !important;
font-size: 16px;
font-weight: 600;
text-decoration: none;
transition: opacity 0.2s ease, transform 0.2s ease;
}
.custom-404-button:hover {
color: #fff !important;
opacity: 0.9;
transform: translateY(-1px);
}
.custom-404-divider {
width: 100%;
height: 1px;
margin: 60px 0 45px;
background: currentColor;
opacity: 0.12;
}
.custom-404-search {
margin-bottom: 20px;
}
.custom-404-page h2 {
margin: 0 0 20px;
font-size: 24px;
line-height: 1.3;
font-weight: 600;
}
.custom-404-search-box {
display: flex;
max-width: 600px;
margin: 0 auto;
}
.custom-404-search-box input {
flex: 1;
min-width: 0;
height: 50px;
padding: 0 16px;
border: 1px solid #ddd;
border-radius: 6px 0 0 6px;
font-size: 16px;
outline: none;
}
.custom-404-search-box input:focus {
border-color: var(--accent, #1e73be);
}
.custom-404-search-box button {
height: 50px;
padding: 0 22px;
border: 0;
border-radius: 0 6px 6px 0;
background: var(--accent, #1e73be);
color: #fff;
font-size: 16px;
font-weight: 600;
cursor: pointer;
}
.custom-404-search-box button:hover {
opacity: 0.9;
}
@media (max-width: 600px) {
.custom-404-page {
padding: 60px 18px 80px;
}
.custom-404-number {
letter-spacing: -3px;
}
.custom-404-description {
font-size: 16px;
}
.custom-404-search-box {
display: block;
}
.custom-404-search-box input {
width: 100%;
margin-bottom: 10px;
border-radius: 6px;
}
.custom-404-search-box button {
width: 100%;
border-radius: 6px;
}
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
if (!document.body.classList.contains('error404')) {
return;
}
var article = document.querySelector(
'.site-content .inside-article'
);
if (!article) {
return;
}
article.innerHTML = `
<div class="custom-404-page">
<div class="custom-404-inner">
<div class="custom-404-number">
404
</div>
<h1>
Oops! Page not found.
</h1>
<p class="custom-404-description">
The page you're looking for may have been moved,
deleted, or no longer exists. Let's get you back on track.
</p>
<div class="custom-404-actions">
<a
class="custom-404-button"
href="/"
>
← Back to Home
</a>
</div>
<div class="custom-404-divider"></div>
<div class="custom-404-search">
<h2>
Search the website
</h2>
<form
role="search"
method="get"
action="/"
>
<div class="custom-404-search-box">
<input
type="search"
name="s"
placeholder="Search the website..."
aria-label="Search the website"
>
<button type="submit">
Search
</button>
</div>
</form>
</div>
</div>
</div>
`;
});
</script>
Step 4: Save and Test the 404 Page
After publishing the Hook Element, open a URL on your website that doesn’t exist.
For example:
yourdomain.com/this-page-does-not-exist/
You should see your new custom 404 design instead of the standard GeneratePress 404 content.
It’s a good idea to test the page on both desktop and mobile devices.
Why Include a Search Box?
A search box is one of the most useful features you can add to a 404 page.
Instead of leaving visitors with only a “Page not found” message, you give them another way to find the information they’re looking for.
For content-heavy websites, blogs, magazines, and business websites with many pages, this can make the 404 page considerably more useful.
Keep Your 404 Page Simple
A common mistake is adding too much content to a 404 page.
You don’t need to display every category, every page, or a large number of links.
A simple structure works well:
404
Oops! Page not found.
A short explanation helps visitors understand the problem.
Back to Home
A prominent button gives visitors an immediate way to return to your main website.
Search the website
The search field provides another route to your content.
This combination keeps the page clean while still giving visitors useful options.
Is a Custom 404 Page Good for SEO?
A custom 404 page does not directly improve your search rankings simply because it looks better. However, it can improve the user experience when visitors encounter broken or outdated URLs.
The important SEO principle is to make sure legitimate missing URLs return a proper 404 HTTP status code rather than pretending that every missing URL is a normal page.
You should also avoid automatically redirecting every nonexistent URL to your homepage. A genuine missing page should generally remain a genuine 404 unless there is a relevant replacement page.
Custom 404 Page Best Practices
For a professional GeneratePress 404 page, keep these best practices in mind:
Use a clear heading
Visitors should immediately understand that the requested page wasn’t found.
Provide a way home
A prominent homepage button gives visitors an easy next step.
Add search
Search is particularly useful on websites with a large amount of content.
Make it mobile-friendly
Your 404 page should work properly on smartphones and tablets as well as desktop screens.
Match your website design
Use your existing typography, spacing, and brand colors so the 404 page feels like part of your website.
Don’t overload the page
Avoid unnecessary animations, advertisements, or excessive navigation.
Frequently Asked Questions
Can I create a custom 404 page with GeneratePress Premium?
Yes. GeneratePress Premium’s Elements functionality can be used to customize how content is displayed on 404 pages.
Do I need a child theme?
Not necessarily. Using a GeneratePress Hook Element allows you to customize the 404 experience without directly editing the GeneratePress theme files.
Can I add a search box to a GeneratePress 404 page?
Yes. A standard WordPress search form can be added to your custom 404 design.
Is the custom 404 page responsive?
The CSS in this tutorial includes responsive rules so the layout adapts to smaller screens.
Should I redirect every 404 page to the homepage?
Generally, no. Automatically redirecting every nonexistent URL to the homepage can make it harder for search engines and visitors to understand that the requested URL doesn’t exist. Use relevant redirects when appropriate and return a genuine 404 for URLs that have no replacement.
Final Thoughts
Creating a custom GeneratePress 404 page doesn’t have to be complicated. With a Hook Element, you can create a professional design that gives visitors a clear message, a direct route back to your homepage, and a convenient search option.
The most important thing is to keep the design simple and useful. A good 404 page should help visitors recover from a broken link rather than simply telling them that something went wrong.
If you’re using GeneratePress Premium, this approach gives you a lightweight way to create a customized 404 experience while keeping the design consistent with the rest of your WordPress website.