老有小可爱咨询问WordPress主题能不能添加禁止QQ微信访问网站,提示其它浏览器打开,有一种解决方案:不让用户在QQ、微信、QQ浏览器打开,方法代码如下:
1、在主题目录下新建:no_QQ.php
以大咖主题举例 ,主题目录则是://wp-content/themes/daka/
2、复制如下代码到no_QQ.php文件保存
- <?php
-
-
- // nocache_headers(); //禁止浏览器缓存
-
- $currentPage = home_url(add_query_arg(array()));
- if ( !strpos($ua, 'qqbrowser/') && !strpos($ua, 'micromessenger') && !strpos($ua, 'qq/') ) {
- $currentPage = home_url();
- }
-
- $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
-
- if ( !strpos($ua, 'micromessenger') && !strpos($ua, 'qq/')&& !strpos($ua, 'qqbrowser/') ) {
-
- // wp_redirect( $currentPage );
-
- }else{
- $blogname = get_bloginfo('name');
- $sep = apply_filters( 'document_title_separator', '-' );
- // $sep = ' '.$sep.' ';
- ?>
- <!DOCTYPE HTML>
- <html lang="zh-CN">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="robots" content="noindex,nofollow">
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
- <meta http-equiv="Cache-Control" content="no-transform" />
- <meta http-equiv="Cache-Control" content="no-siteapp" />
- <title><?php echo $blogname.$sep.get_bloginfo('description'); ?></title>
- <meta content="yes" name="apple-mobile-web-app-capable">
- <meta content="black" name="apple-mobile-web-app-status-bar-style">
- <meta name="format-detection" content="telephone=no">
- <meta name="aplus-touch" content="1">
- <meta name="aplus-touch" content="1">
- <link rel="shortcut icon" href="<?php echo $favicon; ?>" />
- <link rel="icon" href="<?php echo $favicon; ?>" />
-
- <style>
- body,html{width:100%;height:100%}
- *{margin:0;padding:0}
- body{background-color:#fff}
- #contens{margin:105px 0px 10px;text-align:center;font-size:19px;font-weight: 600;margin-bottom:125px;color:#000}
- #contens>div{line-height:130%;margin:10px 0}
- .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}
- .top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
- .app-download-tip{margin:0 auto;text-align:center;font-size:19px;color:#000}
- .app-download-tip .guidance-desc{background-color:#fff;padding:0 10px}
- .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}
- </style>
- </head>
- <body>
-
- <div class="top-bar-guidance">
- <p>点击右上角<img src="https://pic.rmb.bdstatic.com/bjh/6a9abb7fa71efd22efe6731a2ab3a986.png" class="icon-safari"> <span id="openm">浏览器打开</span></p>
- <p>可以继续浏览本站哦~</p>
- <div id="contens"><b>
- <div><span style="color:#ff0000;" >"<?php echo $blogname; ?>温馨提示"</span></div>
- <div>本站禁止在<span style="color:#0056ff;">|微信|QQ|QQ浏览器|</span>内打开</div>
- <div style="display: none;">请使用除<span style="color:#0056ff;">|QQ浏览器|</span>外的手机浏览器访问</div>
- </b>
- </div>
- </div>
- <div class="app-download-tip"><span class="guidance-desc">您可以复制本站网址到其它浏览器打开</span></div>
- <a data-clipboard-text="<?php echo $currentPage; ?>" class="app-download-btn" id="ASpaycopyurl">点此复制本站网址</a>
-
- <script src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js"></script>
- <script>
- var ua = navigator.userAgent;
-
- var clipboard = new ClipboardJS('#ASpaycopyurl');
- clipboard.on('success', function(e) {
- document.getElementById("ASpaycopyurl").innerHTML='复制成功';
- });
- clipboard.on('error', function(e) {
- alert('复制失败,请点击右上角用浏览器打开');
- });
-
- </script>
- </html>
- <?php die;} ?>
3、在主题的function.php文件中,最后一行,插入如下代码:
- /****************禁止腾讯系列访问*****************************/
-
- include("/www/wwwroot/www.bugaoshini.com/wp-content/themes/daka/no_QQ.php") ;
完事,收工!
© 版权声明
THE END
暂无评论内容