Site logo

Archived topic

Hide sidebar on custom 404 error page

7 replies · Started by Randy on September 30, 2021

Viewing posts 1–8 of 8

Ok, getting somewhere I think Leo!

I created two Elements:
- A Block-Hook Element set to generate_do_tempalate_part assigned to Location 404 Template: This has the contents of the 404 page
- A Layout Hook Element set to Location 404 Template that has only Content shown (no sidebars)

That successfully hides the sidebar on the 404 error. (Kind of complicated to set up a 404 error page, but if that's the easiest approach, that ok!)

One final follow-up. How do I disable the AdSense ad that is trying to load? The ad is currently loaded as a Hook Element assigned to generate_after_header. It's in a div with the class rlmtopaddiv. How do I disable that on this 404 page?

I tried using something like this in the functions.php, but that didn't work:
add_action('generate_after_header', function() {
if ( is_404() ) {
//not sure what to put here
}
});

Sample page below

The ad is currently loaded as a Hook Element assigned to generate_after_header.

In that case couldn't you just add the 404 page to the exclusion rule?

Ah, great! I didn't realize you could add the 404 Template as an exclusion rule. That worked! Thanks Leo!

No problem :)

This archived topic is closed to new replies.