<
Neerav Mehta
Founder & CEO
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';
}
}
Create two files in your theme directory:
Now, simply add your codes in these files and have fun!!
Neerav Mehta
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.
Let’s get you started!