Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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.

    #997214

    Hey 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,
    Victoria

    #997218

    Hi 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 :-/

    #997346

    Hi,

    It is better to check with your hosting provider, some times configurations are different.

    Best regards,
    Basilis

    #997516

    Hi 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 5 years, 8 months ago by dogsbody.
    #997598

    Hi dogsbody,

    Did you make this file too includes/error410 ?

    Looks ok, maybe it is some configuration missing?

    Best regards,
    Victoria

    #997614

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

    #998141

    Hey!

    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,
    Peter

    #999408

    Didn’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(); ?>
    #999423

    Hi!

    Try to add the code I posted to the child theme functions.php

    Regards,
    Peter

    #999463

    Hi 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

    #999549

    Hi,

    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,
    Dude

    #1000408

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

    #1001748

    Hi,

    Thanks for the suggestion. We’ll look into it if we get more requests for 410 templates.

    Best regards,
    Dude

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Creating a 410.php’ is closed to new replies.