Site logo

Archived topic

Change the text 404 error

30 replies · Started by Gustavo on June 20, 2015

Viewing posts 1–15 of 31

Hi Tom,

I would change the text of 404 error. How can I do?

You 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';
}

Thanks Tom!

You're welcome :)

Hi 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,
Markus

Thanks 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,
Markus

Thanks, 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,
Markus

I 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 :)

Thanks 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 80

error 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!
Markus

No 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.

Thanks, Tom! Will do!

Bests,
Markus

Hi 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,
Helen

This archived topic is closed to new replies.