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2Nrcy1oZWFkaW5nPSIyMjRkMGU4YjQzNjJhMDBiZjJmYzcwNTQwNzdiOWI2NiJdICB7IGZvbnQtc2l6ZTogMzZweDtmb250LXdlaWdodDogYm9sZDtjb2xvcjogcmdiYSggMjU1LCAyNTUsIDI1NSwgMSApO3RleHQtYWxpZ246IGNlbnRlcjsgfSAgQG1lZGlhIG9ubHkgc2NyZWVuIGFuZCAobWF4LXdpZHRoOiA3ODFweCkgeyAudGItY29udGFpbmVyIC50Yi1jb250YWluZXItaW5uZXJ7d2lkdGg6MTAwJTttYXJnaW46MCBhdXRvfSAgfSBAbWVkaWEgb25seSBzY3JlZW4gYW5kIChtYXgtd2lkdGg6IDU5OXB4KSB7IC50Yi1jb250YWluZXIgLnRiLWNvbnRhaW5lci1pbm5lcnt3aWR0aDoxMDAlO21hcmdpbjowIGF1dG99aDEudGItaGVhZGluZ1tkYXRhLXRvb2xzZXQtYmxvY2tzLWhlYWRpbmc9IjIyNGQwZThiNDM2MmEwMGJmMmZjNzA1NDA3N2I5YjY2Il0gIHsgZm9udC1zaXplOiAxNnB4OyB9ICAgfSA=

Original

How to build a custom 404 page with GeneratePress

generatepress.com
Back to Articles
July 29, 2021, added by Stuart Read
#Wordpress, #GeneratePress, #GenerateBlocks, #404 Page

Custom 404 Page

If you use GeneratePress  3 (plus pro) with wordpress and want to create a custom 404 page there are a couple of things you need to do to get this working for you.

I use GenerateBlocks (plus pro) from the guys that make GeneratePress as well, and love it – simple and effective.

GeneratePress has a default 404 page that contains the following:

  • Title
  • Text
  • Search

You used to need to use the GeneratePress custom PHP filters to either change the messaging or turn these off and create your own custom page but this is no longer necessary with the new action: generate_do_template_part.

I’ll give both versions just in case anyone need them.

New Way

In the wordpress admin section navigate to menu items “Appearance” > “Elements” .

Select “Add New Element” – then choose element type: Block and create.

Once the page opens select the the location of ‘404 template’ under ‘Display Rules’.

On the right you will now need to hook this in to the template and to do this we will need to use the new custom action.

Select “Custom Hook” and then enter the custom hook name: generate_do_template_part.

This will replace the standard template loop item with whatever you have in designed in the main body of your new Block Element.

The old way

First up you’ll need to add some custom code to either your functions.php or use a plugin to house all your little code changes to the site.

I use the Toolset suite of plugins (Paid) that has this functionality, but I also use the plugin “Code Snippets” which is really good.

Code Snippets

If you are going to use the functions.php file I would suggest creating a child theme as its will be easier moving forward with any other customisations you may have.

Title filter

add_filter( 'generate_404_title','generate_custom_404_title' );
function generate_custom_404_title()
{
return '';
}

Body text filter

add_filter( 'generate_404_text','generate_custom_404_text' );
function generate_custom_404_text()
{
return '';
}

Remove the search

add_filter( 'get_search_form','my_remove_search_form' );
function my_remove_search_form()
{
$template = $GLOBALS['template'];
$template_file = substr($template, strrpos($template, '/') + 1);
if ($template_file === '404.php') {
return '';
}
}

Add the above code to either your custom code tool or your fucntions.php file, save and test a 404 page… you should see a blank canvas apart from maybe the header and footer if you have these setup.

After you have added the above code you can follow the instructions from the new method, however this time you will use another hook action.

before_main_content is what I used to use for this.

Then design the page as you see fit and save.

 

Conclusion

That’s about it, all very easy and you can create custom 404 pages in GeneratePress with ease now and if you think about how you can now use the new generate_do_template_part to alter other templates loop sections if you see the need.


Link Notes

if you use GeneratePress and want to create a custom 404 page there are a couple of things you need to do to get started.

Hover link location
- generatepress.com

All Tags
#Wordpress, #GeneratePress, #GenerateBlocks, #404 Page

Modified on: July 29, 2021

Send me something

Please validate reCAPTCHA

Confirmation

Done! Thanks for that... I'll be in touch if its not spam :)

About

How To Use

Curation Policy

Categorisation

Website List

Sitemap

All Right Reserved StuartRead.com 2025
Not Logged in
New Article
View Articles
Website List
Contact Stuart
Login with Google