采用WordPress代码将文章中的部分内容隐藏,通过注微信公众号自动回复获取查看验证码。

放点吸引人的玩意,可以增加公众号的粉丝。

这个是一个无需插件即可使用的方法:

一、将下面的代码,添加到当前主题函数模板 functions.php 文件中:

记得修改代码中自己的微信公众号名称:


function weixin_fans($atts, $content=null){
extract(shortcode_atts( array (
'key' => null,
'reply' => ''
), $atts));
// 管理员登录直接显示隐藏内容
if ( current_user_can('level_10') ) {
return '<div class="hidden-content">'.do_shortcode( $content ).'</div>';
}
// 输入正确验证码显示隐藏内容
if(isset($_POST['weixin_key']) && $_POST['weixin_key']==$key){
return '<div class="hidden-content">'.do_shortcode( $content ).'</div>';
} else {
return '
<form class="post-password-form weixin-form" action="'.get_permalink().'" method="post">
<div class="weixin-box">
<div class="post-secret"><i class="be be-info"></i>输入验证码查看隐藏内容:</div>
<p>
<input id="wpbox" type="password" size="20" name="weixin_key">
<input type="submit" value="提交" name="Submit">
</p>
<div class="weixin-secret">
<div class="weixin-w">扫描二维码关注本站微信公众号或者在微信里搜索:<span class="weixin-n">TOP顶尖文案网馆</span></div>
<div class="weixin-w">回复 <span class="weixin-n">'.$reply.'</span> 获取验证码</div>
<img src="https://wenan.top/wp-content/uploads/2021/05/gzh.png" alt="weixin">
</div>
</div>
</form>';
}
}
add_shortcode('weixin', 'weixin_fans');


提示:因代码中有中文,所以修改保存 functions.php 文件时,模版编码选择:UTF-8 无BOM(无签名),否则中文会显示乱码。

二、css样式:添加到主题样式文件中或者外观 → 自定义 → 额外CSS中

.hidden-content, .weixin-form {
padding: 0.5rem 0.5rem;
border: 1px dashed #ff5e52;
}
.weixin-n {
color: #ff4400;
}
.weixin-form img {
width: 150px;
height: auto;
}

三、使用方法:

编辑文章时分别输入自动回复的验证码和回复的内容:

[(删除红色内容)weixin key=验证码 reply=回复的内容]隐藏的内容[/weixin]

然后在公众号设置关键词自动回复即可!