Create an exit or redirect page

In this article, we explain how to create a redirect or exit page. Here's an example:

Example of an "Exit Page"
1

Create a custom plugin

If you haven't done so already, create a custom plugin.

2

Add custom code

Add the following custom code to your custom plugin:

/**
 * This modifies the affiliate link and redirects the link back to the site's
 * homepage with specific query parameters added.
 */
add_filter( 'dfrapi_after_affiliate_id_insertion', 'mycode_redirect_to_exit_page', 20, 3 );
function mycode_redirect_to_exit_page( $url, $product, $affiliate_id ) {


	$args = array(
		'dfrapi_id'          => $product['_id'],
		'dfrapi_url'         => urlencode( $url ),
		'dfrapi_name'        => urlencode( $product['name'] ),
		'dfrapi_brand'       => urlencode( $product['brand'] ),
		'dfrapi_merchant'    => urlencode( $product['merchant'] ),
		'dfrapi_merchant_id' => $product['merchant_id'],
	);


	$url = trailingslashit( get_home_url() ) . 'dfrapi-redirect';


	return add_query_arg( $args, $url );
}


/**
 * This overrides the loading of a template file and creates a lightweight bounce page
 * to display a "redirect" message and the logo of the merchant you are redirecting to.
 */
add_filter( 'template_include', 'mycode_exit_page_template', 99 );
function mycode_exit_page_template( $template ) {


	// Get query parameters.
	$id          = ( isset( $_GET['dfrapi_id'] ) ) ? urldecode( $_GET['dfrapi_id'] ) : false;
	$url         = ( isset( $_GET['dfrapi_url'] ) && ! empty( $_GET['dfrapi_url'] ) ) ? urldecode( $_GET['dfrapi_url'] ) : false;
	$name        = ( isset( $_GET['dfrapi_name'] ) ) ? urldecode( $_GET['dfrapi_name'] ) : false;
	$brand       = ( isset( $_GET['dfrapi_brand'] ) ) ? urldecode( $_GET['dfrapi_brand'] ) : false;
	$merchant    = ( isset( $_GET['dfrapi_merchant'] ) ) ? urldecode( $_GET['dfrapi_merchant'] ) : false;
	$merchant_id = ( isset( $_GET['dfrapi_merchant_id'] ) ) ? urldecode( $_GET['dfrapi_merchant_id'] ) : false;


	// Return if required parameters are not available.
	if ( ! $url || ! $id ) {
		return $template;
	}
	?>


    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <meta name="robots" content="noindex">
        <meta http-equiv="refresh" content="3;url=<?php echo $url; ?>">
        <title>Redirecting to <?php echo $name; ?></title>
        <style type="text/css">


            body {
                margin-top: 100px;
                font-family: sans-serif;
                font-size: 16px;
            }


            .wrapper {
                margin-right: auto;
                margin-left: auto;
                text-align: center;
                padding: 30px;
                max-width: 400px;
                border-radius: 25px;
                box-shadow: 0 10px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) !important;
            }


        </style>
    </head>
    <body>
    <div class="wrapper">
        <p>
            You are being redirected to <strong><?php echo $merchant; ?></strong>&hellip;
        </p>
        <p>
            <img src="https://images.datafeedr.com/m/<?php echo $merchant_id; ?>.jpg" border="0"/>
        </p>
        <p>
            If you don't wish to wait, <a href="<?php echo $url; ?>">click here</a>.
        </p>
    </div>
    </body>
    </html>
    
	<?php
	// Do NOT edit below this line.
	die();
	exit;
}

Now your 'buy' links will display a redirect message and 3 seconds later, load the merchant's website.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us