支持关注微信公众号获取查看验证码WordPress教程

作者:30115776@qq.com

很多站长想要增加公众号粉丝,可以利用隐藏部分内容,通过关注微信公众号自动回复获取查看验证码,今天就为大家分享支持关注微信公众号获取查看验证码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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>你的微信公众号名称</span></div>

<div class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”weixin-w\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>回复 <span class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”weixin-n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.$reply.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'</span> 获取验证码</div>

<img src=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”https://wx3.sinaimg.cn/large/0066LGKLly1g6fs5fgkg6j30nw0nwq5e.jpg\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” alt=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”weixin\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>

</div>

</div>

</form>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

}

}

add_shortcode(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’weixin\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’weixin_fans\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

修改其中的:你的微信公众号名称

将第11行和24行的$key和\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’.$reply.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ 分别改为固定密码和回复关键词,可以统一密码和关键词,方便批量替换。

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

配套样式:

.hidden-content, .weixin-form {

padding: 0 0.5rem;

border: 1px dashed #ff4400;

}

.weixin-n {

color: #ff4400;

}

.weixin-form img {

width: 150px;

height: auto;

}

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

使用方法:

编辑文章时输入:

[weixin key=验证码 reply=回复的内容]隐藏的内容[/weixin]

分别输入自动回复的验证码和回复的内容

提示:

要注意验证码后面有一个半角的空格,否则输入验证码无效。

代码中无cookie功能,再次打开页面需要重新输入验证码。

管理员登录状态下直接显示隐藏的内容,不需要输入验证码。

短代码虽然目前已被区块编辑器所取代,不过短代码功能还是可以正常使用的。

发表评论