-
AuthorPosts
-
August 14, 2018 at 1:07 pm #997058
I can usually find answers in this forum so am surprised that this seems to be a new one…
I’m using the 410 for WordPress plugin as we are relaunching our site and (while we will be 301 redirecting as many pages as possible) there will be some pages that we are deleting forever.
For a more customised response the plugin advises us to…
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.
I have done this and while I know some very basic PHP I don’t know all the WP function calls. I can’t make a page that both removes all reference to “404” and looks anything like the Enfold theme at the end of it!
Any help gratefully appreciated. Thank you.
August 14, 2018 at 6:33 pm #997214Hey dogsbody,
Try copying the 404.php and rename to 410.php and check if it works first of all and then try to adjust the looks.
Best regards,
VictoriaAugust 14, 2018 at 6:39 pm #997218Hi Victoria,
This is exactly what I did however the page title and breadcrumb menu stayed saying “404” no matter what I put in the 410.php file :-/
August 14, 2018 at 10:32 pm #997346Hi,
It is better to check with your hosting provider, some times configurations are different.
Best regards,
BasilisAugust 15, 2018 at 11:52 am #997516Hi Basilis,
We build Linux servers for living so hosting shouldn’t be the issue. It’s a standard LEMP stack and we use it for hosting hundreds of WP sites.
The 410.php page “works” however the 404.php file we are copying contains so much Enfold stuff that we don’t seem to be able to customise it to say “410 – Gone” :-(
The following is the Enfold 404.php with “404” changed to “410” inside the PHP however the page title and page breadcrum still states “404”!? :-/
<?php if ( !defined('ABSPATH') ){ die(); } global $avia_config; get_header(); echo avia_title(array('title' => __('Error 410 - Gone', 'avia_framework'))); do_action( 'ava_after_main_title' ); ?> <div class='container_wrap container_wrap_first main_color <?php avia_layout_class( 'main' ); ?>'> <?php do_action('avia_410_extra'); ?> <div class='container'> <main class='template-page content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content'));?>> <div class="entry entry-content-wrapper clearfix" id='search-fail'> <?php get_template_part('includes/error410'); ?> </div> </main> <?php $avia_config['currently_viewing'] = 'page'; ?> </div> </div> <?php get_footer(); ?>
- This reply was modified 6 years, 3 months ago by dogsbody.
August 15, 2018 at 4:43 pm #997598Hi dogsbody,
Did you make this file too includes/error410 ?
Looks ok, maybe it is some configuration missing?
Best regards,
VictoriaAugust 15, 2018 at 5:11 pm #997614Hi Victoria,
We did try making the includes/error410 and have also tried pulling it into the file itself (see below).
I have set this up for you to see. If you browse to THIS PAGE you can see what I was talking about. The page title and breadcrumb trail still says “404”.
This is our current 410.php file and as you can see it has no reference to “404”
<?php if ( !defined('ABSPATH') ){ die(); } global $avia_config; get_header(); echo avia_title(array('title' => __('Error 410 - Gone', 'avia_framework'))); do_action( 'ava_after_main_title' ); ?> <div class='container_wrap container_wrap_first main_color <?php avia_layout_class( 'main' ); ?>'> <?php do_action('avia_410_extra'); ?> <div class='container'> <main class='template-page content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content'));?>> <div class="entry entry-content-wrapper clearfix" id='search-fail'> <p class='entry-content'><strong><?php _e('This page has been removed', 'avia_framework'); ?></strong><br/> <?php _e('Sorry, we\'ve had a tidy up and the the post you\'re looking for has been removed.<br/><br/>Maybe you want to perform a search?', 'avia_framework'); ?> </p> <?php if(isset($_GET['post_type']) && $_GET['post_type'] == 'product' && function_exists('get_product_search_form')) {get_product_search_form();} else {get_search_form();} ?> <div class='hr_invisible'></div> <section class="410_recommendation"> <p><strong><?php _e('For best search results, mind the following suggestions:', 'avia_framework'); ?></strong></p> <ul class='borderlist-not'> <li><?php _e('Always double check your spelling.', 'avia_framework'); ?></li> <li><?php _e('Try similar keywords, for example: tablet instead of laptop.', 'avia_framework'); ?></li> <li><?php _e('Try using more than one keyword.', 'avia_framework'); ?></li> </ul> <div class='hr_invisible'></div> <?php do_action('ava_after_content', '', 'error410'); ?> </section> </div> </main> <?php $avia_config['currently_viewing'] = 'page'; ?> </div> </div> <?php get_footer(); ?>
Please help. Thank you.
August 16, 2018 at 8:29 pm #998141Hey!
You can try to use the wp_410_response action (plugin action) and the avf_title_tag filter (Enfold title filter) to customize the title tag like:
add_action('wp_410_response','avia_set_410_status', 10); function avia_set_410_status() { global $avia_config; $avia_config['is_410'] = true; } add_filter('avf_title_tag', 'avia_change_title_tag', 10, 2); function avia_change_title_tag($title, $wptitle) { global $avia_config; if(!empty($avia_config['is_410'])) { $title = '410 – Gone'; } return $title; }
Best regards,
PeterAugust 20, 2018 at 3:17 pm #999408Didn’t make any difference but I’m not sure I am putting it in the right place?…
<?php if ( !defined('ABSPATH') ){ die(); } global $avia_config; add_action('wp_410_response','avia_set_410_status', 10); function avia_set_410_status() { global $avia_config; $avia_config['is_410'] = true; } add_filter('avf_title_tag', 'avia_change_title_tag', 10, 2); function avia_change_title_tag($title, $wptitle) { global $avia_config; if(!empty($avia_config['is_410'])) { $title = '410 – Gone'; } return $title; } get_header(); echo avia_title(array('title' => __('Error 410 - Gone', 'avia_framework'))); do_action( 'ava_after_main_title' ); ?> <div class='container_wrap container_wrap_first main_color <?php avia_layout_class( 'main' ); ?>'> <?php do_action('avia_410_extra'); ?> <div class='container'> <main class='template-page content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content'));?>> <div class="entry entry-content-wrapper clearfix" id='search-fail'> <p class='entry-content'><strong><?php _e('This page has been removed', 'avia_framework'); ?></strong><br/> <?php _e('Sorry, we\'ve had a tidy up and the the post you\'re looking for has been removed.<br/><br/>Maybe you want to perform a search?', 'avia_framework'); ?> </p> <?php if(isset($_GET['post_type']) && $_GET['post_type'] == 'product' && function_exists('get_product_search_form')) {get_product_search_form();} else {get_search_form();} ?> <div class='hr_invisible'></div> <section class="410_recommendation"> <p><strong><?php _e('For best search results, mind the following suggestions:', 'avia_framework'); ?></strong></p> <ul class='borderlist-not'> <li><?php _e('Always double check your spelling.', 'avia_framework'); ?></li> <li><?php _e('Try similar keywords, for example: tablet instead of laptop.', 'avia_framework'); ?></li> <li><?php _e('Try using more than one keyword.', 'avia_framework'); ?></li> </ul> <div class='hr_invisible'></div> <?php do_action('ava_after_content', '', 'error410'); ?> </section> </div> </main> <?php $avia_config['currently_viewing'] = 'page'; ?> </div> </div> <?php get_footer(); ?>
August 20, 2018 at 3:58 pm #999423Hi!
Try to add the code I posted to the child theme functions.php
Regards,
PeterAugust 20, 2018 at 4:24 pm #999463Hi Peter,
Ahh, sorry, that has now been added to the functions.php.
Still no joy though. I feel i should be calling the new functions somehow though?
I tried adding
do_action('wp_410_response');
to my 410.php but that didn’t seem to make a difference.I have ensured that all caching is turned off while we do this.
Regards, Dan
August 20, 2018 at 6:40 pm #999549Hi,
The problem is Enfold doesn’t check for a 410 status. We need to rely on the plugin which calls
do_action('wp_410_response');
on line 364 in wp-410.php ( https://plugins.trac.wordpress.org/browser/wp-410/trunk/wp-410.php#L364 ).
The wp_title() filter ( https://developer.wordpress.org/reference/hooks/wp_title/ ) which is used by Enfold to set the title tag in the head section is called before your custom 410.php template, thus you can’t add the code to your template. You could try to include the plugin code in our filter function like:
add_filter('avf_title_tag', 'avia_change_title_tag', 10, 2); function avia_change_title_tag($title, $wptitle) { global $avia_config; global $wpdb; $table = $wpdb->prefix . '410_links'; $links = $wpdb->get_results( "SELECT gone_key, gone_regex FROM $table WHERE is_404 = 0", OBJECT_K ); $req = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $req = rawurldecode( $req ); foreach( $links as $link ) { if( @preg_match( $link->gone_regex, $req ) ) { $title = '410 – Gone'; break; } } return $title; }
to determine if it’s a 410 page or not. I haven’t tried to code myself but it should be a starting point. You can add it to the functions.php. This code should work without the code I posted before (do not combine both code snippets).
Best regards,
DudeAugust 22, 2018 at 3:50 pm #1000408No such luck :-(
Giving up now I’m afraid. Can I please suggest that you add a 410.php file as a feature request in future versions. A lot of us are very wary of Google and support for this plugin would be awesome.
Thank you for trying.
August 25, 2018 at 7:56 pm #1001748Hi,
Thanks for the suggestion. We’ll look into it if we get more requests for 410 templates.
Best regards,
Dude -
AuthorPosts
- The topic ‘Creating a 410.php’ is closed to new replies.