源码介绍:
- 功能是只有关注公众号并回复关键字获取验证码后,才能查看到文章中的隐藏内容。
- 这个功能插件也可以实现,但我更喜欢代码实现,今天分享给各位
![图片[1]-WordPress为文章添加设置隐藏内容关注公众号可见-99源码屋](https://tu.99yiz.com/2021/12/20211225063320596.png?imageView2/0/format/webp/q/75)
教程开始
- 将以下代码放入在主题目录下functions.php文件里面最下面,然后下面的代码复制进去即可。
- 实际运行可把代码中的二维码及名称更换成自己的
/**
* WordPress 文章部分内容关注微信公众号后可见
* 99源码屋修改美化 www.99yiz.com 项目
*/
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
'<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="gzhhide">
<div ><img class="gzhcode" align="right" src="https://zhoudadatool.gitee.io/mizhi/98dou/98doutc/wp-content/uploads/2021/08/gzh.png" width="130" height="130" alt="99源码屋"></div>
<div class="gzhtitle">抱歉!隐藏内容,请关注[公众号]输入关键词密码后可见!<i class="fa fa-lock"></i><span></span></div>
<div class="gzh-content">请打开微信扫描右边的二维码回复关键字“<span><b>'.$keyword.'</b></span>”获取密码,也可以微信直接搜索“【99源码屋】”关注微信公众号获取密码。</div>
<div class="gzhbox"><form action="'.get_permalink().'" method="post">
<input id="pwbox" type="password" size="20" name="secret_key">
<button type="submit">立即提取</button></form></div></div>';
}
}
add_shortcode('gzh2v', 'lxtx_secret_content');
3. 你只需在网站管理后台—》主题设置—》自定义代码—》自定义 CSS 样式,把下面的 CSS 代码复制粘贴到里面即可。
4、编写文章内添加简码实现-最核心步骤
[gzh2v keyword="公众号关键词" key="设置密码"] 隐藏内容[/gzh2v]
如下图所示:
![图片[2]-WordPress为文章添加设置隐藏内容关注公众号可见-99源码屋](https://tu.99yiz.com/2021/12/20211225064310858.png?imageView2/0/format/webp/q/75)
感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
请登录后发表评论
注册
社交帐号登录