最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Redirect website domain (including all pages) to external URL after Popup message (few seconds)

programmeradmin1浏览0评论

I am new to wordpress and I have made custom code as below. Where I can place this custom code in wordpress. I want to redirect the website domain and all pages but wanted to display popup message for few seconds (3 to 5) and automatically redirect to any external URL.

<script type="text/javascript">   
    function Redirect() 
    {  
        window.location=""; 
    } 
     $(window).on('load',function(){
        $('#myModal').modal('show'); 
        setTimeout('Redirect()', 5000);  
    });
</script>

<div class="container">
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Beaumondevillas are part of Natural Retreats</h4>
        </div>
        <div class="modal-body">
          <p>We are redirecting the Natural Retreats Palm Spring Page</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

I am new to wordpress and I have made custom code as below. Where I can place this custom code in wordpress. I want to redirect the website domain and all pages but wanted to display popup message for few seconds (3 to 5) and automatically redirect to any external URL.

<script type="text/javascript">   
    function Redirect() 
    {  
        window.location="https://example"; 
    } 
     $(window).on('load',function(){
        $('#myModal').modal('show'); 
        setTimeout('Redirect()', 5000);  
    });
</script>

<div class="container">
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Beaumondevillas are part of Natural Retreats</h4>
        </div>
        <div class="modal-body">
          <p>We are redirecting the Natural Retreats Palm Spring Page</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>
Share Improve this question edited May 15, 2019 at 20:37 Nisarg asked May 15, 2019 at 20:02 NisargNisarg 1013 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

"Where" somewhat depends on the theme you're using. Here's couple examples,

  1. If you have a custom made theme, then you can put the code in any appropriate place. For example header.php (after <head>) or footer.php.

  2. If you have child theme, then you can copy a suitable template_part file from the parent theme to the child dir and add the code to that file.

  3. Add the code with a action/filter hook. For example wp_footer (although the button might look a bit silly with this one) or append it to the_content.

  4. If you don't need to show the redirected domains content, you could create custom page template and page to which you first redirect all users with template_redirect (or template_include) to serve as a landing page. Then include your custom redirect modal on that page.

发布评论

评论列表(0)

  1. 暂无评论