Skip to main content
Became Hot Network Question
edited tags
Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

hide Hide title if 404 error

Source Link
turpentyne
  • 477
  • 4
  • 17

hide title if 404 error

I have a custom 404 error page, and I just want a quick module that hides the 404 page title, if the user arrives at a 404 error.

I've found a D7 function that looks like it would work, checking for '404 Not Found' in the http header, and adding a class that I can target with CSS. But I'm not sure how I'd do something like this for D8.

Here's what I've got:

function MYMODULE_preprocess_html(&$variables) {
  $headers = drupal_get_http_header();

  if (isset($headers['status']) && $headers['status'] == '404 Not Found') {
    $variables['classes_array'][] = 'page-404';
  }
}