纯代码实现WordPress公众号涨粉功能

实现效果如下图

下面介绍实现方法:

1、添加涨粉核心函数

主题functions.php文件添加代码

//涨粉功能核心代码
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
'<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://ae01.alicdn.com/kf/H845a1462df1e415abc0d09fd8d682aa3N.jpg" width="165" height="165" alt="公众号【松子分享】"></div>
<div class="gzhtitle">抱歉!内容已隐藏,输入密码后可见!<i class="fa fa-lock"></i><span></span></div>
<div class="gzh-content">打开微信扫一扫,关注本站公众号,回复“<strong><span><b>'.$keyword.'</b></span></strong>”获取密码。您也可以微信搜索【松子分享】关注获取。</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('ghide', 'secret');

2、添加 CSS 样式

在主题自带的自定义css样式功能里添加或者

WordPress后台,依次选择【外观】-【自定义】-【额外CSS】

/*内容隐藏样式*/
.gzhhide .secret-password{background: none repeat scroll 0 0 #efe;border-left: 5px solid #3B8CFF;color: #555;padding: 10px 0 10px 10px;border-radius: 5px;margin-bottom: 15px;overflow:hidden; clear:both;}
.gzhhide .post-secret{font-size: 18px; line-height:20px; color:#3B8CFF; margin:5px;}
.gzhhide form{ margin:15px 0;}
.gzhhide form span{ font-size:18px; font-weight:700;}
.gzhhide .erweima{ margin-left:20px; margin-right:16px;}
.gzhhide 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;}
.gzhhide 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;}

.gzhhide .gzhcode{position:absolute;width:100px;height:100px;right:20px;top:50%;margin-top:-50px}
.gzhhide{background:#fff;border-radius:10px;padding:20px;margin:15px 0;position:relative;box-shadow:0 0 20px #d0d0d0}
.gzhhide .gzhtitle{position:relative;font-size:17px;font-weight:700;color:#6c80a7;padding:6px 140px 0 40px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.gzhhide .gzhtitle .fa{position:absolute;left:0;font-size:35px;top:0}
.gzh-content{padding:20px 140px 15px 0;font-size:14px;color:#777}
.gzhbox{padding:0 140px 10px 0}
.gzhbox input{
    width:24%;
    border:none;
    color:#737373;
    font-size:13px;
height:35px;line-height:35px;background:#f2f2f2;border-radius:4px;
outline:none;float:left;padding:0 10px}
.gzhbox button{margin-left:5%;border:none;background:#3b8cff;color:#fff;padding:5px 10px;font-size:14px;border-radius:5px}
.gzhhide .gzhcode{position:absolute;width:120px;height:120px;right:30px;top:27%;margin-top:-20px}
.gzhbox{padding:0}.gzh-content{width:80%;padding:20px 90px 15px 0}
.gzhhide .gzhcode{width:120px;height:120px}#vivideo{height:200px}
.gzhhide .gzhtitle i {font-style:normal;}

3、简码的使用

到这一步就可在后台使用简码了

【ghide keyword=”验证码” key=”设置的验证码”】隐藏内容【/ghide】

注:上面【】改成英文[ ],参数说明(均可修改):

隐藏内容:回复正确验证码后显示的隐藏内容,比如:资源链接;

验证码:提示用户在公众号发送的关键词,每次使用可不一样;

设置的验证码:公众号设置回复的验证码,每次使用可不一样。

如果不嫌麻烦可以一个回复对应一个验证码

4、添加简码按钮

为了写文章时快速插入简码,可在文章编辑器上添加简码按钮

同样将其添加到 functions.php,简码标签名“公众号隐藏”可任意修改

//文章编辑器添加简码按钮
function wpsites_add_gzh_quicktags() {
    if (wp_script_is('quicktags')){
?>
    <script type="text/javascript">
    QTags.addButton( 'ghide', ' 公众号隐藏', '\n[ghide keyword="验证码" key="szfx"]隐藏内容[/ghide]', "" );
    </script>
<?php
    }
}
add_action( 'admin_print_footer_scripts', 'wpsites_add_gzh_quicktags' );

5、参考资料

钻芒博客-为WordPress文章添加公众号引流模块

本文采用 CC BY-NC-SA 3.0 Unported 许可,转载请以超链接注明出处。
原文地址:纯代码实现WordPress公众号涨粉功能 作者:松鼠小
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
Source: Telegram @AmashiroNatsukiEars_NoWord Sticker
Source: Github @zhheo/Sticker-Heo
Source: github.com/k4yt3x/flowerhd
颜文字
AmashiroNatsukiEars
Heo
小恐龙
花!
上一篇
下一篇