微信一直是热门中的重点,有时候经常看见许多wordpress博客的部分文章需要关注微信公众号才能查看,或者某些下载地址需要关注微信公众号才可以查看,这个功能确实不错,可以吸粉,也可以引流,不过步骤稍微麻烦了点,容易导致客户失去兴趣或者放弃浏览。
很早之前就有人分享过有这么一个 wordpress 插件,关注公众号并回复关键字获取验证码后,才能查看到文章中的隐藏内容。但是插件只能实现所有文章只能设置一个验证码,不能分别为单个文章设置,不是很方便。且有些同学可能并不喜欢插件版的,今天给大家分享一个代码版的,纯代码实现WordPress文章部分内容关注微信公众号后可见,而且该代码可实现自动将关键词选择为文章ID,自己对应为文章设置验证码就行了。
1、核心代码
将以下代码放入functions.php中:
- // WordPress文章部分内容关注微信公众号后可见
- function lxtx_secret_content($atts, $content=null){
- extract(shortcode_atts(array(‘key’=>null,’keyword’=>null), $atts));
- if(isset($_POST[‘secret_key’]) && $_POST[‘secret_key’]==$key){
- return ‘<div class=“secret-password”>’.$content.'</div>’;
- } else {
- return
- ‘<div class=“post_hide_box”>
- <img class=“erweima” align=“right” src=“https://cdn.gunmu.cn/wp-content/uploads/2019/07/gunmugongzhong.jpg” width=“150” height=“150” alt=“滚木文化”><div class=“post-secret”><i class=“fa fa-exclamation-circle”></i>此处内容已经被作者无情的隐藏,请输入验证码查看内容</div>
- <form action=“‘.get_permalink().'” method=“post”>
- <span>验证码:</span><input id=“pwbox” type=“password” size=“20” name=“secret_key”>
- <a class=“a2” href=“javascript:;”><input type=“submit” value=“提交” name=“Submit”></a>
- </form>
- <div class=“details”>请打开微信,搜索公众号“滚木文化”或扫描右侧二维码关注微信公众号,回复 <span style=“color:#E53333;”><b>“‘.get_the_ID().'”</b></span> <b>获取验证码</b>。</div>
- </div>’;
- }
- }
- add_shortcode(‘gzh2v’, ‘lxtx_secret_content’);
2、前端CSS美化样式
将以下代码放入网站的css文件内即可:
- .post_hide_box, .secret-password{background: none repeat scroll 0 0 #efe;border-left: 5px solid #e74c3c;color: #555;padding: 10px 0 10px 10px;border-radius: 5px;margin-bottom: 15px;overflow:hidden; clear:both;}
- .post_hide_box .post-secret{font-size: 18px; line-height:20px; color:#e74c3c; margin:5px;}
- .post_hide_box form{ margin:15px 0;}
- .post_hide_box form span{ font-size:18px; font-weight:700;}
- .post_hide_box .erweima{ margin-left:20px; margin-right:16px;}
- .post_hide_box input[type=password]{ color: #9ba1a8; padding: 6px; background-color: #f6f6f6; border: 1px solid #e4e6e8; font-size: 12px;-moz-transition: border .25s linear,color .25s linear,background-color .25s linear; -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear; -o-transition: border .25s linear,color .25s linear,background-color .25s linear; transition: border .25s linear,color .25s linear,background-color .25s linear;}
- .post_hide_box input[type=submit] { background: #F88C00; border: none; border: 2px solid;border-color: #F88C00; border-left: none; border-top: none; padding: 0px;width: 100px; height: 38px; color: #fff; outline: 0;border-radius: 0 0 2px 0; font-size: 16px;}
- .post_hide_box .details span{color:#e74c3c;}
集成短代码
为了方便使用,在后台文本编辑器中集成该短代码。将以下代码放入 functions.php 中即可:
- // 后台文本编辑框中添加公众号隐藏简码按钮
- function lxtx_wpsites_add_gzh_quicktags() {
- if (wp_script_is(‘quicktags’)){
- ?>
- <script type=“text/javascript”>
- QTags.addButton( ‘gzh2v’, ‘ 公众号隐藏’, ‘\n[gzh2v keyword=“关键字” key=“验证码”]隐藏内容[/gzh2v]’, “” );
- </script>
- <?php
- }
- }
- add_action( ‘admin_print_footer_scripts’, ‘lxtx_wpsites_add_gzh_quicktags’ );
4、使用方法
最后我们最重要的一步就是如何使用,这里直接编辑文章的时候切换文本模式插入短代码即可:
[gzh2v keyword=”关键字” key=”验证码”]隐藏内容[/gzh2v]
你让我想到了可以搞一个微信扫描进小程序直接获取验证码 ✗咧嘴笑✗
好早的文章,老古董老古董
我很久之前就已经自己研究出来代码了 https://manman.qian.lu/1491.html 实际上就是密码可见增加了公众号获取密码!!