Search
Generic filters
Exact matches only
Search in title
Search in content
Filter by Categories
PHP Script
Plugin
Codecanyon
Crocoblock
Easy Digital Downloads
Elegantthemes
Gravityperks
MainWP WordPress Manager
Thrive
Ultimate Member
WeDevs
Woocommerce
Yithemes
Yoast
Themes
Themeforest
Elegantthemes
Studiopress
Themify Themes

How to create a download link redirect page in WordPress

For those of you who do data-sharing blogs, in addition to making money with Google Adsence on shared articles, creating a redirect page when downloading and then embedding the ad code in it will increase your income. Today FreeWP shows you how to create download link redirect page in WordPress.

Step 1: Create a page in the theme folder in use

Go to the source code of your wordpress website: wp-content\themes\theme you are using. Create a file page–redirect-link.php or create it on your computer and then upload this file to the theme directory.

download link redirect page

Open the newly created file, copy the code below and paste it and save the file.

Template 1:

tempalate 1
<?php
/*
Template Name: Redirect Page
*/
 
$redirect_to = !empty($_GET['url'])
? trim(strip_tags(stripslashes($_GET['url'])))
: '';
 
$wait_time = 30000; // auto navigation time (in milliseconds - here 30000 ml = 30s).
$wait_seconds = $wait_time / 1000;
 
add_action('wp_head', 'redirect_to_no_index', 99);
function redirect_to_no_index()
{
?>
<!-- disable indexing of this page -->
<meta name="robots" content="noindex, follow">
<?php
}
 
add_action('wp_head', 'redirect_to_external_link');
 
function redirect_to_external_link()
{
global $redirect_to, $wait_seconds, $wait_time;
 
if (empty($redirect_to) || empty($wait_time)) {
return;
}
?>
 
<script>var redirect = window.setTimeout(function(){window.location.href='<?php esc_html_e($redirect_to); ?>'},<?php echo $wait_time; ?>);</script>
<noscript><meta http-equiv="refresh" content="<?php echo $wait_seconds; ?>;url=<?php esc_attr_e($redirect_to); ?>">></noscript>
<?php } get_header(); ?>
 
 
<div class="redirect-page">
<div>
<?php if (!empty($redirect_to)) {
echo '<p style="font-size: 95%;margin: 8px !important; color: #fff;">You want to move to:</p>';
printf(__('<div style="margin: 8px !important;word-wrap: break-word;">%s</div>'),esc_html($redirect_to));
?>
<p><span class="redirect-timer" id="timer"></span></p>
<div style="margin-top:20px">
<button id="redirect-get" onclick="window.location.href='<?php esc_html_e($redirect_to); ?>';return false;"><?php _e('✓ GO NOW'); ?></button>
<button id="redirect-close" onclick="self.close()"><?php _e('✘ CANCEL'); ?></button> <br />
</div>
 
<?php
} else {
_e('This link is broken or does not exist!');
}
?>
</div>
</div>
<script>
document.getElementById('timer').innerHTML = <?php echo $wait_seconds;?>;
var timer = <?php echo $wait_seconds;?>;
var interval = setInterval(function() {
var seconds = timer;
if (seconds > 0) {
--seconds;
document.getElementById('timer').innerHTML = seconds + "";
timer = seconds;
}
else {
 
}
 
}, 1000);
</script>
<style>
.redirect-page{max-width:1400px;margin-top:50px;margin-bottom:50px;margin-left:auto;margin-right:auto;text-ailgn:center;text-align: center;}
#redirect-get{margin: 7px;background: #00cc00; border: 1px solid #00cc00; color: #fff; cursor: pointer; font-size: 13px ; font-weight: bold ; padding: 7px 15px;text-decoration: none;text-transform: uppercase;text-shadow: none;}
#redirect-close{background: #ff4444; border: 1px solid #ff4444; color: #fff; cursor: pointer; font-size: 13px ; font-weight: bold ; margin-bottom: 10px;padding: 7px 15px;text-decoration: none;text-transform: uppercase;text-shadow: none;}
#redirect-get:hover, #redirect-close:hover{background: #555; border: 1px solid #555}
.redirect-timer{color:#ff3333;font-size:50px;margin-top: 30px;}
</style>
<?php get_footer(); ?>

Template 2:

FreeWP is using this template

tempalate 2
<?php
/*
Template Name: Redirect Page
*/

// get the redirection url from GET variable
$redirect_to = !empty($_GET['url'])
 ? trim(strip_tags(stripslashes($_GET['url'])))
 : '';
 
$wait_time    = 20000; // auto navigation time (in milliseconds - here 30000 ml = 30s).
$wait_seconds = $wait_time / 1000;
 
add_action('wp_head', 'redirect_to_no_index', 99);
function redirect_to_no_index()
{
?>
   <!-- disable indexing of this page -->
  <meta name="robots" content="noindex, follow">

<?php
}
 
add_action('wp_head', 'redirect_to_external_link');

function redirect_to_external_link()
{
    global $redirect_to, $wait_seconds, $wait_time;
    
    if (empty($redirect_to) || empty($wait_time)) {
    return;
    }
    ?>

    <script>var redirect = window.setTimeout(function(){window.location.href='<?php esc_html_e($redirect_to); ?>'},<?php echo $wait_time; ?>);</script>
    <noscript><meta http-equiv="refresh" content="<?php echo $wait_seconds; ?>;url=<?php esc_attr_e($redirect_to); ?>">></noscript>
  
 <?php
}
 
get_header(); //show headers 
?> 
<div class="textwidget custom-html-widget"><div class="widget-content">
<a class="sora-ads-here" href="javascript:;">Responsive Advertisement</a>
<style>
.sora-ads-here {
  display: block;
    background-color: #eee;
    text-align: center;
    font-size: 13px;
    color: #aaaaaa;
    font-weight: 400;
    font-style: italic;
    line-height: 90px;
    border: 1px solid #ccc;
}
</style>
</div></div>
 <div id="redirect-page-content"  style="width: 100%; background:#fff; height: 50%; margin: 0px 0px 0px 0px; text-align: center; font-size: 18px;">
        <div class="redirect-message">
        <?php if (!empty($redirect_to)) {
        //echo '<p style="font-size: 95%;margin: 8px !important; color: #191919;">YOU ARE TRANSFED TO THE FILE DOWNLOAD PAGE</p>';
        //printf(__('<strong style="margin: 8px !important;">%s</strong>'),esc_html($redirect_to));
        ?>
         <p style="font-size: 90%;margin: 8px 0px 15px 0px !important;color: #f50c0c;"><strong>AUTOMATICALLY GO TO DOWNLOAD FILE PAGE IN <span style="color: #2fad16" id="timer"></span> SEC </strong></p> 
        
         <?php
        } else {
        _e('The redirect link is broken');
        }
        ?>
        </div>
 </div>
<script>
document.getElementById('timer').innerHTML = <?php echo $wait_seconds;?>;
var timer = <?php echo $wait_seconds;?>;
var interval = setInterval(function() {
   var seconds = timer;
   if (seconds > 0) {
    --seconds; 
    document.getElementById('timer').innerHTML = seconds + "";
   timer = seconds;
   }
   else {
  
   }
  
 }, 1000);
</script>

<?php  
 get_footer(); //show footer
?>
<div class="textwidget custom-html-widget"><div class="widget-content">
<a class="sora-ads-here" href="javascript:;">Responsive Advertisement</a>
<style>
.sora-ads-here {
  display: block;
    background-color: #eee;
    text-align: center;
    font-size: 13px;
    color: #aaaaaa;
    font-weight: 400;
    font-style: italic;
    line-height: 90px;
    border: 1px solid #ccc;
}
</style>
</div></div>

Note: To add ads to the redirect page you find 2 lines:

get_header(); //show headers
?>
 get_footer(); //show footer
?>

Step 2: Create Redirect page in wordpress admin

Go to wordpress admin page > Pages > Create new page (Add New)

Create Redirect page in wordpress admin
Screenshot 11

In there:

  • Title: Redirect Link (optional)
  • Url Slug: redirect-link
  • Page Attributes – Templates: Redirect Page
  • Then select Publish the newly created page.

Install Better WordPress External Links. Don’t worry it’s very light, doesn’t affect web speed

setting btw

Then go to Setting > BWP External Links > External link prefix > choose A custom URL

In section Custom URL prefix, you fill out the following form (as in the picture above): https://yourdomain/redirect/?url=

Besides

You can choose the link location (Process links inside) or remove the domain you don’t want to redirect (Forced local domains) as shown below

Better WordPress External Links Settings

Then click save to finish the installation.

Accomplished! You go to see the article and enjoy the results

You want to insert ads, copy the ad code to insert into the desired display position. If you can’t do it, you can ask a technician or you can use this plugin: WP Safelink -Converter Your Download Link To Adsense

Above is the most basic code file to redirect website links. You can customize more depending on your needs. Any questions you can ask in the comments section below. Or message this facebook link for answers.