让WORDPRESS文章中部分内容隐藏,输入密码后显示

发布时间:2021-08-01 17:10 最后更新:2023-03-23 16:08 浏览量:共 47 次浏览

在主题下找到 /wp-content/themes/主题目录名/functions.php,然后在最尾添加以下代码:

/*e-secret 添加VIP加密内容输入密码后才能查看*/
function e_secret($atts, $content=null){
extract(shortcode_atts(array('key'=>null), $atts));
if(isset($_POST['e_secret_key']) && $_POST['e_secret_key']==$key){
return '
<div class="e-secret-content">'.$content.'</div>
';
}
else{
return '
<form class="e-secret" action="'.get_permalink().'" method="post" name="e-secret"><label><font color=red><strong>以下内容是仅供本站VIP会员查看,全站密码相同,详情请咨询客服:</strong></font></label><input type="password" name="e_secret_key" class="euc-y-i" maxlength="50"><input type="submit" class="euc-y-s" value="确定">
<div class="euc-clear"></div>
</form>
';
}
}
add_shortcode('secret','e_secret');

以上代码复制出去。

使用方法:
在文本下,把要隐藏的内容前后加上:

[  secret key="密码"]

要隐藏的内容【用时要去掉 [ 后面的空格】

[  /secret]

 

效果演示如下【密码是123456】:

相关文章

调所有前端VUE,标题四个字,超过自动调行,字和框竖向自动居中
【Simply Static生成静态失败】宝塔防火墙拦截了服务器本机访问自身域名 / IP 的环回请求
zhong zhuan
宝塔面板中如何修改网站顺序
Ubuntun和debian 系统升级
【教程】Simply Static配置详情