手動(dòng)代碼實(shí)現(xiàn)WordPress內(nèi)容加密密碼顯示開啟

麥子 優(yōu)化維護(hù)136字?jǐn)?shù) 1932閱讀6分26秒閱讀模式

考慮到自媒體引流的需要,我們會(huì)將部分的內(nèi)容加密顯示,獲取密碼可以提示讓從公眾號(hào)設(shè)置特殊關(guān)鍵字獲取。這里我們前提是需要將WordPress部分內(nèi)容隱藏起來。當(dāng)然,有一些主題是支持的,也有一些常見。這里我們無需插件也可以實(shí)現(xiàn)。

1、CSS代碼部分

.e-secret {
margin: 20px 0;
padding: 20px;
background: #f8f8f8;
}
.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:#3498db;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:#5dade2;}
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;}

2、加密功能

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.'</div>
';
}
else{
return '
<form class="e-secret" action="'.get_permalink().'" method="post" name="e-secret"><label>輸入密碼查看加密內(nèi)容:</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');

加入到 Functions.php 中。

3、調(diào)用顯示

[secret key="設(shè)置密碼"]
需要加密的內(nèi)容部分
[/secret]

根據(jù)提示,我們可以將需要加密的部分隱藏。

投上你的一票
 
  • 本文由 麥子 發(fā)表于 2024年12月31日 17:17:22
  • 轉(zhuǎn)載請(qǐng)務(wù)必保留本文鏈接:http://bjj.org.cn/wpencipher-content.html
  • WordPress加密內(nèi)容