How to display the sitemap on the 404 page in Drupal 8?

Member

by drew , in category: SEO , a year ago

How to display the sitemap on the 404 page in Drupal 8?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by hanna , 10 months ago

@drew 

To display the sitemap on the 404 page in Drupal 8, you can follow these steps:

  1. Create a new custom block: Go to Structure > Block Layout and click on "Custom Block Library". Then click on "Add custom block" and provide a block title such as "Sitemap".
  2. Add the sitemap content: In the block configuration screen, you can add the sitemap content using any appropriate markup or template.


For example, you can use the following code to generate a basic unordered list of the sitemap links:

1
2
3
4
5
{% set sitemap = drupal_render(attachment_load('your_sitemap_attachment_id')) %}


  {{ sitemap }}


Replace 'your_sitemap_attachment_id' with the attachment ID of your sitemap. You can find the attachment ID by going to Content > Files and locating the sitemap file.

  1. Configure the block placement: After adding the sitemap content, configure the block placement by clicking on the "Place block" button. Choose a region where you want the sitemap to appear, such as the "Footer" or "Content" region.
  2. Display the block on the 404 page: To display the block on the 404 page, you need to configure the block visibility settings. Click on the "Layout" tab and locate the region where you placed the sitemap block. Click on the corresponding region settings button (e.g., "Configure") and choose "Show for specific pages" under the "Visibility" section.
  3. Set the 404 page path: In the "Pages" field, enter the path for the 404 page, which is usually "/404". Save the changes.


Now, the sitemap block should be displayed on the 404 page in Drupal 8.