今天上午老蒋看到有网友在讨论如何隐藏网站页面中的部分内容,比如有些核心的代码和技术问题希望隐藏起来。让用户通过手动输入密码来显示出来。当然不要整个篇幅都隐藏起来,这样会影响用户体验和搜索引擎的体验,只是部分隐藏起来不会有多大影响的。
这里可以实现的办法还是蛮多的,简单一点就直接用密码隐藏。

/核心代码部分 itbulu.com/  
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 '  

'.$content.'

';

}  
else{  
    return '  



';

}  

}
add_shortcode('secret','e_secret');


这个代码添加到当前的主题功能页面中。
.e-secret {

margin: 20px 0;  
padding: 20px;  
background: #f8f8f8;  
overflow: auto;  

}
.e-secret input.euc-y-i[type=“password”] {

float: left;  
background: #fff;  
width: 100%;  
line-height: 36px;  
margin-top: 5px;  
border-radius: 3px;  

}
.e-secret input.euc-y-s[type=“submit”] {

float: right;  
margin-top: -47px;  
width: 30%;  
margin-right: 1px;  
border-radius: 0 3px 3px 0;  

}
input.euc-y-s[type=“submit”]{background-color:#FF0016;color:#fff;font-size:21px;box-shadow:none;-webkit-transition: .4s;-moz-transition: .4s;-o-transition: .4s;transition:.4s;-webkit-backface-visibility:hidden;position:relative;cursor:pointer;padding: 13px 20px;text-align: center;border-radius: 50px;-webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none;border: 0;height: auto;outline: medium;line-height: 20px;margin: 0;}
input.euc-y-s[type=“submit”]:hover{background-color:#CE0416;}
input.euc-y-i[type=“text”],input.euc-y-i[type=“password”]{border:1px solid #F2EFEF;color:#777;display:block;background: #FCFCFC;font-size:18px;transition:all .5s ease 0;outline:0;box-sizing:border-box;-webkit-border-radius:25px;-moz-border-radius:25px;border-radius:25px;padding:5px 16px; margin: 0;height: auto;line-height: 30px;}
input.euc-y-i[type=“text”]:hover,input.euc-y-i[type=“password”]:hover{border:1px solid #56b4ef;box-shadow:0 0 4px #56b4ef;}


样式部分不要少,这个根据需要自己再设置。比如我们有些人还将修改成需要扫码公众号获取密码的,也可以实现。后面老蒋看看如何更友好一些。
最后,如果我们需要添加隐藏部分用下面代码包含起来。
[secret key="输入密码"]隐藏内容[/secret]

关于WordPress隐藏内容显示的办法还有很多:
1、WordPress关注微信公众号获取验证码查看隐藏内容
2、WordPress利用Pretty Links插件实现隐藏链接
3、WordPress利用Easy Affiliate Links插件隐藏链接


扫描二维码,在手机上阅读!