[Resolved] custom 410 error page

Home Forums Support [Resolved] custom 410 error page

Home Forums Support custom 410 error page

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #309754
    Steven

    Hi. We’re doing some “house cleaning” on an 8-year old blog and are deleting some smaller, no longer meaningful posts. I found the 410 for WordPress plugin to be convenient but would like to create a custom 410 error page telling a potential visitor the page is gone, not that it can’t be found. I figured I could duplicate and modify GeneratePress’ 404 page in a child theme, but when I looked at it I realized I don’t know how to handle those calls to the “generate_404_text” filter. For something like a simple error page can I sidestep the filters and simply insert html? Or would I be better off figuring out how to create a “generate_410_text” filter?
    Thank you.

    #309855
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I would actually suggest setting up 301 redirects from the old pages to the new pages/page you want to direct people to. Not only is this better for SEO, it’s better for the user as it explains what happened to the post or directs them to the information at the new location.

    #310042
    Steven

    Thank you, Tom. As part of the content refinement process we are indeed doing 301 redirects. Shorter posts with common themes are being merged into longer posts, and the now obsolete posts are being redirected to the longer, more comprehensive version. I’m doing that manually in the .htaccess file.

    However, there are still some posts which have been deemed prune-able. It’s not likely any of those have been linked to by readers but still – I’d like to be able to indicate to the hypothetical visitor that the post has been removed by sending him or her to a custom 410 page.

    Just for background, the blog author (my wife!) listened to an episode of the smart passive income podcast (episode 200) covering the benefits of a content audit, so that’s what we have embarked on.
    Steve

    #310116
    Tom
    Lead Developer
    Lead Developer

    Perhaps this plugin will help do the job: https://en-ca.wordpress.org/plugins/wp-410/

    #310152
    Steven

    Thank you, Tom. I have this very plugin already installed. In the plugin’s description is this: “If you want to customise the message, just place a template file called 410.php in your theme folder, and the plugin will automatically use that instead. Take a look at your theme’s 404.php file to see how the template needs to be structured.”
    That’s what I’m trying to achieve – creating a specific 410.php template file! I looked at GeneratePress’ 404.php template and noticed calls to the “generate_404_text” filter. I’m seeking tips on how to make a custom 410.php template file based on the existing 404.php file. I’m sorry if I wasn’t more clear when I asked the question initially. Thanks again for your interest.
    Steve

    #310260
    Tom
    Lead Developer
    Lead Developer

    Ah, sorry for misunderstanding!

    Ok, so first you need to install a child theme: https://docs.generatepress.com/article/using-child-theme/

    Then, copy the 404.php file, and put it in your child theme folder.

    Then you can change the name to 410.php, and alter the text however you like inside the template file.

    #310311
    Steven

    Cool.
    So I have already created a super tiny child theme to accomplish another goal.
    I understand copying the 404.php template file and changing its name to 410.php in the child theme directory.
    My uncertainty was around calls to the functions “generate_404_title” and “generate_404_text”
    For example:
    <?php echo apply_filters( 'generate_404_text', __( 'It looks like nothing was found at this location. Maybe try searching?', 'generatepress' ) ); ?>

    If (in the new 410.php template file) I change the above to something like
    <?php echo apply_filters( 'generate_404_text', __( 'This post has been removed', 'generatepress' ) ); ?>

    it should work in spite of not being a 404 error? I was wondering if I could just side-step the function call and slap in some plain HTML. Is there any advantage to using apply_filters?

    I hope I haven’t been too much of a pain. I’m grateful for your help and suggestions.
    Steve

    #310339
    Tom
    Lead Developer
    Lead Developer

    You can just remove those filters completely and add your own text.

    So:

    <?php echo apply_filters( 'generate_404_text', __( 'It looks like nothing was found at this location. Maybe try searching?', 'generatepress' ) ); ?>

    Would become:

    This post has moved! More info here..

    #310494
    Steven

    Perfect – thanks so much! I’m glad for the reassurance that I don’t have to over-complicate a small error page which isn’t likely to get hit very often. Thank you for your time and patience.
    Steve

    #310566
    Tom
    Lead Developer
    Lead Developer

    No problem! Glad I could help 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.