• Resolved jumbo

    (@jumbo)


    Hi. First, thanks for this great plugin. Would it be possible to use a custom 410 template instead of just outputting wp_die() gray page with a single optional message?

    I’d like to provide more information on the page, a logo, and a link to the homepage with a custom design.

    For instance, place a 410.php template within the theme folder that’ll load up? I know there are some dedicated 410 plugins in the plugin repository that support custom 410 templates, but I’d like to use Safe Redirect Manager as it already has 410 support instead of installing two plugins.

    Thanks.

    • This topic was modified 9 months, 2 weeks ago by jumbo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Darin Kotter

    (@dkotter)

    Thanks for the question. When we added more full support for 410 error codes, there was a discussion around trying to load a template if that exists. We ultimately ended up not going in that direction and instead just output a message using wp_die() as you’ve noted.

    This is something that could be brought up for discussion again if you’d like to open a new issue on GitHub but for now, you can achieve what you want using core WordPress hooks.

    The wp_die() function ends up running a filter around the callback it uses. You can use this filter to load a custom template for 410 codes.

    As an example:

    add_filter(
    	'wp_die_handler',
    	function () {
    		return 'custom_wp_die_handler';
    	}
    );

    And then write a function, custom_wp_die_handler() that loads the template you want. This function will have the message and error code passed in that you can then check to ensure you only load your template on a 410 request.

    function custom_wp_die_handler( $message = '', $title = '', $args = array() ) {
    	if ( isset( $args['response'] ) && 410 === $args['response'] ) {
    		include_once get_query_template( '410' );
    		return;
    	}
    
    	_default_wp_die_handler( $message, $title, $args );
    }

    I quickly tested the above and it does work but you’ll need to ensure how you load the 410 template works for your use case.

    Thread Starter jumbo

    (@jumbo)

    Thanks @dkotter. This is great. I can work with that. Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom 410 template?’ is closed to new replies.