- This topic has 30 replies, 8 voices, and was last updated 6 years, 8 months ago by Tom.
-
AuthorPosts
-
June 20, 2015 at 4:37 am #115721Gustavo
Hi Tom,
I would change the text of 404 error. How can I do?
June 20, 2015 at 9:44 am #115744TomLead DeveloperLead DeveloperYou can use the built in filters.
For example:
add_filter( 'generate_404_title','generate_custom_404_title' ); function generate_custom_404_title() { return 'Custom 404 title'; } add_filter( 'generate_404_text','generate_custom_404_text' ); function generate_custom_404_text() { return 'Custom 404 text'; }
June 20, 2015 at 9:50 am #115751GustavoThanks Tom!
June 20, 2015 at 1:12 pm #115783TomLead DeveloperLead DeveloperYou’re welcome π
October 17, 2015 at 12:18 pm #145246MarkusHi Tom,
I noticed that in the new update (1.3.16) the 404 text can be updated.
So is there an easy way to create a custom 404 page with generate press now?
All best,
MarkusOctober 17, 2015 at 11:14 pm #145319TomLead DeveloperLead DeveloperHi Markus,
The best way is still what I mentioned above in this topic: https://generatepress.com/forums/topic/change-the-text-404-error/#post-115744
October 18, 2015 at 9:20 am #145403MarkusThanks for your quick answer, Tom!
But where would I need to paste that snippet?
Also, I am not entirely sure yet as to where I would style the 404 page. In the code itself? Do I just need to replace the “Custom 404 text” string, for example?
Best wishes,
MarkusOctober 18, 2015 at 10:14 am #145415TomLead DeveloperLead DeveloperThat’s correct, you would use this function:
add_filter( 'generate_404_text','generate_custom_404_text' ); function generate_custom_404_text() { return 'Your 404 text in here'; }
And add is using these instructions: https://generatepress.com/knowledgebase/adding-php-functions/
October 18, 2015 at 11:40 am #145439MarkusThanks, Tom! Working through the child theme option I actually became aware of the
appearance > editor > 404 template
section, which I haven’t used in the past. I am not sure if this is any way connected to the child theme, but I strongly suspect this was to have been there before. In that case it would have been perfectly fine for me to simply edit the 404 page through the regular GP theme.
I am just adding this here to help those looking for the same information after me π
Best wishes,
MarkusOctober 18, 2015 at 11:44 am #145441TomLead DeveloperLead DeveloperI wouldn’t edit that file as you will lose your edits when you update GeneratePress.
Using the function I provided in a child theme/custom plugin will ensure you won’t lose your edits ever π
October 18, 2015 at 12:16 pm #145443MarkusThanks for the clarification, Tom! I actually thought this is what would happen. But, frankly, the template that comes with GP works perfectly for me, after all.
The only reason why I was starting to look for a customization function is because I thought there was no 404 page. But, strangely enough, when I enter a URL with a wrong page ID, e.g.
http:/myURL/?page_id=78
I do reach GP’s 404 page (with my header and everything, obviously). But when looking for something like
http:/myURL/Fred
I get the standard
Not Found
The requested URL /Fered was not found on this server.
Apache Server at myURL Port 80error message. I am not sure why and, coming to think of it, I am not even sure if this qualifies as a 404 page. But I am perfectly happy knowing that old page URLs that I may have gone offline trigger GP’s 404 response.
Sorry for the confusion!
MarkusOctober 18, 2015 at 2:14 pm #145450TomLead DeveloperLead DeveloperNo worries! You can check with your hosting to make sure the 404 errors are being handled by WordPress.
I also suggest setting your permalinks as “Postname” in “Settings > Permalinks” – the standard ?page_id=xx isn’t very SEO friendly.
October 19, 2015 at 12:28 pm #145769MarkusThanks, Tom! Will do!
Bests,
MarkusMay 17, 2017 at 1:15 pm #319364HelenHi Tom,
Coding newbie question – in which file and where exactly do I add your add_filter code above to change the text of the 404 page please?
Many thanks,
HelenMay 17, 2017 at 3:13 pm #319405LeoStaffCustomer SupportThis should help: https://docs.generatepress.com/article/adding-php/
-
AuthorPosts
- You must be logged in to reply to this topic.