DEV Community

Muhammad Rauf
Muhammad Rauf

Posted on

22 13

How to Create Custom 404 error page

Hello, Do you need to add a custom 404 error page on your website/blog? 404 error happens when a user opens a non-existing page on your website such as an incorrect link, a page that has been deleted, or when the user mistyped a URL.

In this tutorial, you will learn how to add a custom 404 error page on your website/blog. Next, We will describe how to change the title of 404 error pages and prevent them from being indexed by Google.

How to add custom 404 error page

Image description
Here’re steps to adding a custom 404 error page on your WordPress website/blog –

1.First, login to your WordPress Dashboard.
2.Go to Appearance > Theme Editor.
3.Under theme Editor find 404.php option, and click on it.
4.Now copy and paste the following code in the page.

<?php get_header(); ?>
<img src="https://i.ibb.co/W6tgcKQ/softcodeon.gif">
<title>Page Not Found</title>
<h1 class="error-text">Whoops, We can't seem to find the resource you're looking for.</h1>
<p class="text">Please check that the Web site address is spelled correctly.Or,</p>
<div class="button">
<a class="error" href="#">Go to Homepage</a>
</div>
<style>
*{padding:0;margin:0;background:#f0f0f0;}
img{display: block;
  margin-left: auto;
  margin-right: auto;}
  .button{text-align:center;}
 .text{text-align:center;font-size:20px;margin-bottom:40px;}
 .error-text{text-align:center;padding:20px;  font-family: Cursive;
} .error{font-family: 'Roboto', sans-serif;font-size:1.5rem;text-decoration:none;padding:15px;background:#6200ee;color:#fff;border-radius:10px;}
</style>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Enter fullscreen mode Exit fullscreen mode

Finally, tap the “Update File” button.

Note: Please Keep in mind if you have the same classes as I have added in the above code please change them with the unique classes you want. You can also customize the style by adding background color, changing image or Gif, Modify Font Family, and text for the error page.
To prevent Google and other search engines from indexing 404 error pages of your blog Follow this guide to know How to Hide a Page from Google Search

Want to read in detail from official website Create 404 Error page. I'll recommend to add other best page links to your 404 error page.

To see DEMO

I hope you find this guide helpful to customize the 404 error page of your website blog. Please discuss below if you have any question about this simple 404 error page.

Image of Timescale

📊 Benchmarking Databases for Real-Time Analytics Applications

Benchmarking Timescale, Clickhouse, Postgres, MySQL, MongoDB, and DuckDB for real-time analytics. Introducing RTABench 🚀

Read full post →

Top comments (2)

Collapse
 
arizona profile image
Arizona

Would you please make it animated with CSS instead of GIF? Looks good, but where can I get GIFs?

Collapse
 
softcodeon profile image
Muhammad Rauf

Yes, it can be animated by using css. I will post this error page with css animations very soon

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay