纯代码实现WordPress文章部分内容关注微信公众号后可见
发布时间:2025-10-19 14:49:41 本站作者 【 字体:大 中 小 】 浏览:6 次
一、核心代码
将以下代码放入functions.php中:
/** * WordPress文章部分内容关注微信公众号后可见 - 龙笑天下 * http://www.ilxtx.com/view-contents-by-following-wechat-official-accounts.html */ 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="改为二维码图片的网址" 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">请关注“你的名字”官方QQ公众号,回复关键字“<span>'.$keyword.'</span>”,获取验证码。【注】用手机QQ扫描右侧二维码都可以关注“你的名字”官方QQ公众号。</div> </div>'; } } add_shortcode('gzh2v', 'lxtx_secret_content');
PS:注意修改代码中的相关内容!
二、前端CSS样式
将以下代码放到你主题的style.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.1 在文章中使用短代码
插入以下简码,修改相关内容即可:
[gzh2v keyword="关键字" key="验证码"]隐藏内容[/gzh2v]
4.2 微信公众号
这里以微信公众号为例(QQ公众号应该也是这样),在微信公众号的“自动回复-关键字自动回复”中设置好关键字(对应上面代码中的keyword)及验证码(对应上面代码中的key)。
五、延伸
其实本文是跟常见的“文章部分内容回复后看见”或“文章部分内容登录后可见”的代码原理一致,只是结合了一下公众号而已。大家可以动动手集成到自己的主题哈!
热门推荐
广告位-300PX*250PX
最新发布

office2010密钥,office2010激活密钥,office2010永久密钥激活码最新分享

不少用户在求2018最新Microsoft Office 2010产品密钥,office2010密钥有两种,office2010永久密钥和免费版office密钥,office2010激活码最新的已发布很快就失效了,只有kms客户端免费版office激活密钥是永久有效的。下面小编为大家整理分享office2010最新密钥序列号,不区分32位和64位。说明:office2010零售版密钥和kms密钥...

office365激活密钥,小编分享2025最新office365激活码

office365是微软办公套件office的年度服务,那么最近有用户想要office365激活码,过通整理,下面小编把2018年最新office365激活码和激活电脑上office365软件的方法分享给大家。2018年 office365激活码大全:RCBQN-J4MK8-VV3XJ-BPPYB-TXVT77TPNM-PMWKF-WVHKV-G869H-9BQ6XDMXHM-GNMM3-MYHHK-6TVT2-XTKKKG9N...

office2018产品密钥,小编告诉你office2018怎么激活

office2018是微软公司即将发布的一款全新的办公自动化软件,可以说各个行业都必备的;office2018全新版本功能全面升级,具有强大的数据处理、数据计算、图形编辑、演示文稿的制作和文档排版等功能,那么哪里有office2018产品密钥?下面,小编给大家带来了office2018产品密钥。office2018是微软公司开发的一款基于Windows操作...

怎么激活office2019最新版?office 2019激活秘钥+激活工具推荐

最新激活密钥GRBR4-J4N3M-KTX9C-JM4PJ-J8HPT (小编使用的是此激活密钥)NJHVR-FK6XR-M97MB-P8CXD-FM4PJNXVJY-X9T8G-Y6RWG-8VQ7V-PWHPTW8W6K-3N7KK-PXB9H-8TD8W-BWTH9N9J9Q-Q7MMP-XDDM6-63KKP-76FPM9DP6T-9AGWG-KWV33-9MPC8-JDCVF7G2HE-JR8KL-ABB9D-Y7789-GLNFLU2PWU-H7D9H-69T3B-JEYC2-3R2NGR8R8P-MTT6F-KLRPM-J7CAB-PJM8CA4...
大家都在看
office2010密钥,office2010激活密钥,office2010永久密钥激活码最新分享

office365激活密钥,小编分享2025最新office365激活码

office2018产品密钥,小编告诉你office2018怎么激活

怎么激活office2019最新版?office 2019激活秘钥+激活工具推荐

Office2019 激活密钥, Office2019 怎么激活激活?

Office2016激活密钥专业增强版(神Key)Office2016永久激活密钥[2025.10更新]
![Office2016激活密钥专业增强版(神Key)Office2016永久激活密钥[2025.10更新]](/static/upload/image/20251020/1760945332659252.jpg)
office2016永久激活密钥从哪里找?永久激活office2016的方法,一步一步的详细教程来了

office2016怎么激活密钥?office2016怎么安装?今天一文讲清楚

Office2016最新激活密钥分享,office2016密钥永久激活码

office2010永久秘钥是多少 office2010序列号分享 附激活工具
