Menu icon
RedCrackle
Menu icon
Services
01Design Transformation
About UsCase StudiesBlogContact Us

<

Blog post

How to theme 403 and 404 error pages?

Neerav Mehta

Founder & CEO

Drupal allows us to add custom 403 and 404 pages.

Creating custom 403 and 404 pages

  1. Create two nodes, one for 403 and the other for 404.
  2. Navigate to "Configuration" -> "System" -> "Site Information" or admin/config/system/site-information.
  3. Add the paths of the pages into the appropriate fields.
  4. Now every time you visit 403 and 404 pages, you will be redirected to your custom pages.

Setting template suggestion

We can set "theme_hook_suggestions" variable to write our custom template for 403 and 404 pages. It is a special variable that can be set by a pre-processor function in our template.php.

Write the following piece of code in your template.php file or you can add the code in the existing hook_preprocess_HOOK() function.

function THEMENAME_preprocess_page(&$vars) {
  $header = drupal_get_http_header("status");
  if ($header == "404 Not Found") {
    $vars['theme_hook_suggestions'][] = 'page__404';
  }
  elseif ($header == "403 Forbidden") {
    $vars['theme_hook_suggestions'][] = 'page__403';
  }
}

Creating template files

Create two files in your theme directory:

  • page—404.tpl.php
  • page—403.tpl.php

Now, simply add your codes in these files and have fun!!

Neerav Mehta

Neerav Mehta

Founder & CEO

Neerav Mehta is the Founder & CEO of Red Crackle. With sterling qualities, Neerav’s technological acumen is firing a generation of progressive companies on the digital path. With an undergraduate degree in Electrical Engineering from India's most prestigious institution IIT Bombay and having spent seven years developing and contributing to the launch of AMD's innovative line of computer products, Neerav founded Red Crackle where he is lauded for his dynamic and innovative genius.

View all posts

>

Read Next

10 Tips For Entrepreneurs In 2015

10 Tips For Entrepreneurs In 2015

Learn more

10 Ways To Increase Productivity At Work

10 Ways To Increase Productivity At Work

Learn more

30 best WordPress widgets for your site

30 best WordPress widgets for your site

Learn more

Let’s get you started!

Contact Us

>

RedCrackle

Explore

About Us

Services

Contact Us

Our address

5346 Gerine Blossom Dr,

San Jose, CA 95123

USA

Socials

Twitter
LinkedIn

© 2023 RedCrackle. All rights reserved.