光子资源网
光子资源网
光子资源网

WordPress添加禁止QQ微信访问网站,提示其它浏览器打开

老有小可爱咨询问WordPress主题能不能添加禁止QQ微信访问网站,提示其它浏览器打开,有一种解决方案:不让用户在QQ、微信、QQ浏览器打开,方法代码如下:

1、在主题目录下新建:no_QQ.php

以大咖主题举例 ,主题目录则是://wp-content/themes/daka/

2、复制如下代码到no_QQ.php文件保存

  1. <?php
  2. // nocache_headers(); //禁止浏览器缓存
  3. $currentPage = home_url(add_query_arg(array()));
  4. if ( !strpos($ua, 'qqbrowser/') && !strpos($ua, 'micromessenger') && !strpos($ua, 'qq/') ) {
  5. $currentPage = home_url();
  6. }
  7. $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
  8. if ( !strpos($ua, 'micromessenger') && !strpos($ua, 'qq/')&& !strpos($ua, 'qqbrowser/') ) {
  9. // wp_redirect( $currentPage );
  10. }else{
  11. $blogname = get_bloginfo('name');
  12. $sep = apply_filters( 'document_title_separator', '-' );
  13. // $sep = ' '.$sep.' ';
  14. ?>
  15. <!DOCTYPE HTML>
  16. <html lang="zh-CN">
  17. <head>
  18. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  19. <meta name="robots" content="noindex,nofollow">
  20. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
  21. <meta http-equiv="Cache-Control" content="no-transform" />
  22. <meta http-equiv="Cache-Control" content="no-siteapp" />
  23. <title><?php echo $blogname.$sep.get_bloginfo('description'); ?></title>
  24. <meta content="yes" name="apple-mobile-web-app-capable">
  25. <meta content="black" name="apple-mobile-web-app-status-bar-style">
  26. <meta name="format-detection" content="telephone=no">
  27. <meta name="aplus-touch" content="1">
  28. <meta name="aplus-touch" content="1">
  29. <link rel="shortcut icon" href="<?php echo $favicon; ?>" />
  30. <link rel="icon" href="<?php echo $favicon; ?>" />
  31. <style>
  32. body,html{width:100%;height:100%}
  33. *{margin:0;padding:0}
  34. body{background-color:#fff}
  35. #contens{margin:105px 0px 10px;text-align:center;font-size:19px;font-weight: 600;margin-bottom:125px;color:#000}
  36. #contens>div{line-height:130%;margin:10px 0}
  37. .top-bar-guidance{font-size:20px;color:#fff;height:70%;line-height:1.8;padding:20px 20px 0;background:url(http://hao.yt3166.com/assets/img/background.jpg) center top/contain no-repeat}
  38. .top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
  39. .app-download-tip{margin:0 auto;text-align:center;font-size:19px;color:#000}
  40. .app-download-tip .guidance-desc{background-color:#fff;padding:0 10px}
  41. .app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#0056ff;border-radius:20px;border:.5px #0056ff solid;text-decoration:none}
  42. </style>
  43. </head>
  44. <body>
  45. <div class="top-bar-guidance">
  46. <p>点击右上角<img src="https://pic.rmb.bdstatic.com/bjh/6a9abb7fa71efd22efe6731a2ab3a986.png" class="icon-safari"> <span id="openm">浏览器打开</span></p>
  47. <p>可以继续浏览本站哦~</p>
  48. <div id="contens"><b>
  49. <div><span style="color:#ff0000;" >"<?php echo $blogname; ?>温馨提示"</span></div>
  50. <div>本站禁止在<span style="color:#0056ff;">|微信|QQ|QQ浏览器|</span>内打开</div>
  51. <div style="display: none;">请使用除<span style="color:#0056ff;">|QQ浏览器|</span>外的手机浏览器访问</div>
  52. </b>
  53. </div>
  54. </div>
  55. <div class="app-download-tip"><span class="guidance-desc">您可以复制本站网址到其它浏览器打开</span></div>
  56. <a data-clipboard-text="<?php echo $currentPage; ?>" class="app-download-btn" id="ASpaycopyurl">点此复制本站网址</a>
  57. <script src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js"></script>
  58. <script>
  59. var ua = navigator.userAgent;
  60. var clipboard = new ClipboardJS('#ASpaycopyurl');
  61. clipboard.on('success', function(e) {
  62. document.getElementById("ASpaycopyurl").innerHTML='复制成功';
  63. });
  64. clipboard.on('error', function(e) {
  65. alert('复制失败,请点击右上角用浏览器打开');
  66. });
  67. </script>
  68. </html>
  69. <?php die;} ?>

3、在主题的function.php文件中,最后一行,插入如下代码:

  1. /****************禁止腾讯系列访问*****************************/
  2. include("/www/wwwroot/www.bugaoshini.com/wp-content/themes/daka/no_QQ.php") ;

完事,收工!

© 版权声明
THE END
喜欢就支持一下吧
点赞91 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容