一直想找一款微信公众号回复验证码的插件,奈何 wechat-fans 插件不够人性化,只能设置一个验证码,所以就整合了一些大佬的文章,得出以下代码。

在 functions.php 文件中加入以下代码      这个代码必须用 UTF-8-BOM 编码格式(因为有中文),不然直接用主题编辑器修改会错位!!

// WordPress免插件开启公众号涨粉(验证码查看隐藏内容)功能 
function secret($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.5v13.com/wp-content/uploads/2020/08/1597807861-6bdcdcab801e009.png" alt="微信公众号:走客" style="
 width: 380px; margin-top: 20px;"><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>'.$keyword.'</span>”,获取验证码。<br />
            <span>【注】</span>手机扫描二维码快速关注“走客”微信公众号。
	    </div>
         </div>';
      }
}
add_shortcode('ghide', 'secret');
// 文章文本编辑器添加自定义按钮,免得每次都要输入短代码。
function appthemes_add_quicktags() {
?>
<script type="text/javascript">
QTags.addButton( '公众号隐藏', '公众号隐藏', '[ghide keyword="微信验证码" key="163163"]','[/ghide]' ); //实际使用时这里的【】都改成[]
</script>
<?php
}
add_action('admin_print_footer_scripts', 'appthemes_add_quicktags' );

CSS样式文件修改

将下面的代码添加到主题的 style.css 文件中去即可,如果放进 style.css 里边无效的话,可以放进 外观——自定义——额外css  里边

.post_hide_box, .secret-password{
	background: none repeat scroll 0 0 #fcffff;
	border: 1px dashed #24b4f0;
	color: #123456;
	padding: 10px;
	border-radius: 9px;
	margin: 18px 0px;
	overflow:hidden;
	clear:both;
	}
.post_hide_box .post-secret{
	font-size: 18px;
	line-height:20px; 
	color:#24b4f0; 
	margin:5px;
	}
.post_hide_box form{ margin:15px 5px;}
.post_hide_box form span{ font-size:18px; font-weight:bold;}
.post_hide_box .erweima{ margin: 15px;}
.post_hide_box input[type=password]{
	color: #00a0f0;
	background-color: #fff;
	border: 1px solid #24b4f0;
	border-radius: 4px;
	font-size: 12px;
	margin: 0px 5px;
	width: 200px;
	-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: #24b4f0;
    border: none;
    padding: 12px;
    width: 88px;
    color: #fff;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
	}
.details{
	color:#123456;
    font-size: 13px;
	line-height: 30px;
	margin: 5px;
	padding: 3px;
	}
.post_hide_box .details span{color:#e74c3c;}


 

 

发表回复

后才能评论