WordPress 文章部分内容关注微信公众号后可见

其实这个就是美化了下后台加密文章的功能,先贴出我博客美化代码,我也是扒别人的。理论上其他主题也是可以使用的。如果不能使用自行修改。以下代码中 '.get_the_ID().' 会自动获取当前文章的ID作为微信公众号的回复;需要在微信公众号后台设置自动回复“验证码”内容,微信公众号的自动回复设置自行度娘。

0x01 代码

将以下下代码放在 begin 主题的 functions.php 中;

// WordPress文章部分内容关注微信公众号后可见
function wechat_secret_content($atts, $content=null){
 extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
 	// 管理员登录直接显示隐藏内容
	if ( current_user_can('level_10') ) {
		return '<div class="secret-password">'.do_shortcode( $content ).'</div>';
	}
	// 输入正确验证码显示隐藏内容
    if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){
        return '<div class="secret-password">'.$content.'</div>';
    } else {
        return
 '<div class="post_hide_box">
 <img class="erweima" align="right" src="https://www.xxrj.net/wp-content/uploads/2019/09/2019090501504964.jpg" width="150" height="150" alt="运维工程师"><div class="post-secret"><i class="zm zm-kucunjinggao"></i><b>  Sorry~!本文隐藏的内容需要验证码!</b></div>
 <form action="'.get_permalink().'" method="post">
 <span>验证码:</span><input id="pwbox" type="password" size="20" name="secret_key">
 <a class="a2" href="javascript:;"><input type="submit" value="提交" name="Submit"></a>
 </form>
 <div class="details">扫描右侧二维码,关注本站微信订阅号“<span>运维工程师</span>” 或在微信搜索“<span>运维工程师</span>”并关注;</div>
 <div class="details">每篇文章的验证码都不相同,只需关注一次即可;回复“<span>'.get_the_ID().'</span>”获取本文的验证码;</div>
 </div>';
 }
}
add_shortcode('password', 'wechat_secret_content');

0x02 CSS代码

将一下代码放到 begin 主题后台→外观→主题选项→定制风格→自定义样式;CSS代码自行调整;

.post_hide_box, .secret-password {
	background: none repeat scroll 0 0 #efe;
	border-left: 5px solid #e74c3c;
	color: #555;
	padding: 10px 0 10px 10px;
	border-radius: 5px;
	margin-bottom: 15px;
	overflow: hidden;
	clear: both;
}
.post_hide_box .post-secret {
	font-size: 18px;
	line-height: 20px;
	color: #e74c3c;
	margin: 5px;
}
.post_hide_box form {
	margin: 15px 0;
}
.post_hide_box form span {
	font-size: 18px;
	font-weight: 700;
}
.post_hide_box .erweima {
	margin-left: 20px;
	margin-right: 16px;
}
.post_hide_box input[type=password] {
        width: 18%;
	color: #9ba1a8;
	padding: 6px;
	background-color: #f6f6f6;
	border: 1px solid #e4e6e8;
	font-size: 12px;
	-moz-transition: border .35s linear,color .35s linear,background-color .35s linear;
	-webkit-transition: border .35s linear,color .35s linear,background-color .35s linear;
	-o-transition: border .35s linear,color .35s linear,background-color .35s linear;
	transition: border .35s linear,color .35s linear,background-color .35s linear;
}
.post_hide_box 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;
}
.post_hide_box .details span {
	color: #e74c3c;
}

0x03 如何使用

在后台编辑文章的时候,选择编辑器上的“短代码→密码保护”插入到文章即可;这个使用方法适用于Begin主题;

# 也可以在编辑器插入代码,密码为微信公众号回复的内容,加密的内容就是需要隐藏的内容;使用时请将 { } 替换为 [ ]
{password key=密码}加密的内容{/password}

0x04 效果预览

可以直接访问:https://www.xxrj.net/1834.html 预览效果;以下是效果截图;

相关推荐
python ERROR: Command errored out with exit status 1:
Windows Server 2016 搭建 SMB 共享文件
Windows Server 2019 域环境搭建 SMB 共享文件服务
Parallels Desktop 15.1.3