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:

add_filter( 'dfrapi_after_affiliate_id_insertion', function ( $url, $product, $affiliate_id ) {
   return isset( $_GET['dfrapi_id'] )
      ? $url
      : add_query_arg( [ 'dfrapi_id' => absint( $product['_id'] ) ], trailingslashit( get_home_url() ) . 'dfrapi-redirect' );
}, 20, 3 );

add_filter( 'template_include', function ( $template ) {

   $id = trim( $_GET['dfrapi_id'] ?? '' );

   if ( empty( $id ) ) {
      return $template;
   }

   $id = absint( $id );

   if ( ! $post = dfrps_get_post_by_product_id( $id, 'product' ) ) {
      return $template;
   }

   $product = dfrps_product( $post['ID'] );

   if ( empty( $product ) ) {
      return $template;
   }

   $redirect_url = dfrapi_url( $product );
   $name         = $product['name'] ?? '';
   $merchant     = $product['merchant'] ?? '';
   $merchant_id  = absint( $product['merchant_id'] ?? 0 );
   ?>

    <!DOCTYPE html>
    <html lang="en">
    <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 esc_url( $redirect_url ); ?>">
        <title>Redirecting to <?php esc_html_e( $name ); ?></title>
        <style>
            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;
            }

            img {
                border: 0;
            }
        </style>
    </head>
    <body>
    <div class="wrapper">
        <p>
            You are being redirected to <strong><?php esc_html_e( $merchant ); ?></strong>&hellip;
        </p>
        <p>
         <?php printf( '<img src="https://images.datafeedr.com/m/%d.jpg" alt="%s Logo" />', $merchant_id, esc_attr( $merchant ) ); ?>
        </p>
        <p>
            If you don't wish to wait, <a href="<?php echo esc_url( $redirect_url ); ?>">click here</a>.
        </p>
    </div>
    </body>
    </html>

   <?php
   // Do NOT edit below this line.
   die();
}, 99 );

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