前言

最近有小伙伴找文章设置隐藏内容关注公众号才可见,今天就把代码发出来了,代码是在原代码改进而来,不会影响图片灯箱。示例如下,验证码为123456

抱歉!隐藏内容,请输入密码后可见!
请打开微信扫描右侧二维码回复关键字“ID166”获取密码,也可以微信直接搜索“iHuLiKu”关注微信公众号获取密码。

教程开始

首先打开你所使用的主题文件的function.php,在底部加上下面这段代码,请将你的微信公众号二维码图片路径设置好

/*关注微信公众号后可见*/
function weixingzh_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="hidden-box show"><div class="hidden-text">[隐藏内容] - 输入密码后可见</div><div class="secret-password">'.$content.'</div></div>';
    } else {
        return '
        <div class="gzhhide">
            <div class="gzhtitle">抱歉!隐藏内容,请输入密码后可见!<i class="fa fa-lock"></i><span></span></div>
                <div class="gzh-content">请打开微信扫描右侧二维码回复关键字“<span><b>'.$keyword.'</b></span>”获取密码,也可以微信直接搜索“iHuLiKu”关注微信公众号获取密码。
                <div class="gzhcode" style="background: url(https://huliku.com/image/ewm_gzh.png);background-size: 100%;" width="140" height="140" alt="狐狸库"></div>
            </div>
        <div class="gzhbox"><form action="'.get_permalink().'" method="post">
        <input type="password" size="20" name="secret_key">
        <button type="submit">立即提取</button></form></div></div>';
    }
}
add_shortcode('weixingzh', 'weixingzh_secret_content');
function wpsites_add_weixingzh_quicktags() {
    if (wp_script_is('quicktags')){
?>
    <script type="text/javascript">
    QTags.addButton( 'weixingzh', '公众号隐藏', '
        
抱歉!隐藏内容,请输入密码后可见!
请打开微信扫描右侧二维码回复关键字“关键字”获取密码,也可以微信直接搜索“iHuLiKu”关注微信公众号获取密码。
',"" ); </script> <?php } } add_action( 'admin_print_footer_scripts', 'wpsites_add_weixingzh_quicktags' );

将下面的代码加入你的style.css中或者主题自带的自定义CSS样式里,即可实现

使用说明

在你的文章编辑器中加入该短代码即可

温馨提示:本文最后更新于2023/11/15 18:35:08。若文章内容或图片失效,请留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
子比主题文章设置隐藏内容关注公众号可见-狐狸库
子比主题文章设置隐藏内容关注公众号可见
此内容为付费阅读,请付费后查看
500积分
网络收集
虚拟资源
自动发货
永久使用
付费阅读
© 版权声明
THE END
点赞0赞赏 分享
评论 共6条

请登录后发表评论

    请登录后查看评论内容