[Resolved] Change the text 404 error

Home Forums Support [Resolved] Change the text 404 error

Home Forums Support Change the text 404 error

Viewing 15 posts - 1 through 15 (of 31 total)
  • Author
    Posts
  • #115721
    Gustavo

    Hi Tom,

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

    #115744
    Tom
    Lead Developer
    Lead Developer

    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';
    }
    #115751
    Gustavo

    Thanks Tom!

    #115783
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #145246
    Markus

    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

    #145319
    Tom
    Lead Developer
    Lead Developer

    Hi 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

    #145403
    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

    #145415
    Tom
    Lead Developer
    Lead Developer

    That’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/

    #145439
    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

    #145441
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #145443
    Markus

    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

    #145450
    Tom
    Lead Developer
    Lead Developer

    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.

    #145769
    Markus

    Thanks, Tom! Will do!

    Bests,
    Markus

    #319364
    Helen

    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

    #319405
    Leo
    Staff
    Customer Support
Viewing 15 posts - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.