Sunday, October 2, 2022
HomeSeo LearningHow to create a download link redirect page in WordPress

How to create a download link redirect page in WordPress

For anybody who does data-sharing blogs, in addition to earning profits with Google Adsense on shared articles, creating a redirect site when downloading and then embedding the ad code inside will increase your income. Today FreeWP shows you how to build a download URL redirect page in WordPress.

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

Navigate to the source code of your WordPress website: wp-content\themes\theme you are employing. Create a record page–redirect-link. PHP or create it on your computer and then upload this file to the theme directory.

download link redirect page

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

Template 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:

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
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments