- This topic has 9 replies, 2 voices, and was last updated 6 years, 12 months ago by Tom.
-
AuthorPosts
-
April 24, 2017 at 12:18 pm #309754Steven
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.April 24, 2017 at 6:53 pm #309855TomLead DeveloperLead DeveloperHi 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.
April 25, 2017 at 6:36 am #310042StevenThank 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.
SteveApril 25, 2017 at 9:19 am #310116TomLead DeveloperLead DeveloperPerhaps this plugin will help do the job: https://en-ca.wordpress.org/plugins/wp-410/
April 25, 2017 at 9:56 am #310152StevenThank 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.
SteveApril 25, 2017 at 2:16 pm #310260TomLead DeveloperLead DeveloperAh, 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.
April 25, 2017 at 5:32 pm #310311StevenCool.
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.
SteveApril 25, 2017 at 7:35 pm #310339TomLead DeveloperLead DeveloperYou 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..
April 26, 2017 at 6:32 am #310494StevenPerfect – 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.
SteveApril 26, 2017 at 8:53 am #310566TomLead DeveloperLead DeveloperNo problem! Glad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.