Products
GG网络技术分享 2025-03-18 16:13 0
通过WordPress 短代码实现将文章中的部分内容隐藏,通过关注微信公众号自动回复获取验证码,实现公众号的粉丝零突破,哈哈哈。
将下面的代码,添加到当前主题函数模板 functions.php 文件中:
//公众号获取验证码
function weixin_fans($atts, $content=null){
extract(shortcode_atts( array (
'key' => null,
'reply' => ''
), $atts));
// 管理员登录直接显示隐藏内容
if ( current_user_can('level_10') ) {
return '<div class="hidden-content">'.do_shortcode( $content ).'</div>';
}
// 输入正确验证码显示隐藏内容
if(isset($_POST['weixin_key']) && $_POST['weixin_key']==$key){
return '<div class="hidden-content">'.do_shortcode( $content ).'</div>';
} else {
return '
<form class="post-password-form weixin-form" action="'.get_permalink().'" method="post">
<div class="weixin-box">
<div class="post-secret"></i>获取高速下载链接</div>
<p>
<input style="width:120px;height:26px;" type="password" size="18" name="weixin_key">
<input style="width:40px;height:30px;" type="submit" value="提交" name="Submit">
</p>
<div class="weixin-secret">
<div class="weixin-w">回复<span class="weixin-n">'.$reply.'</span>将会获取<span class="weixin-n">验证码</span></div>
<img src="https://defcon.cn/wp-content/uploads/2020/07/qrcode.jpg" alt="weixin">
</div>
</div>
</form>';
}
}
add_shortcode('weixin', 'weixin_fans');记得修改为你的公众号名称
CSS样式,可自行修改调试
.hidden-content, .weixin-form { padding: 20px 0.5rem; border: 2px dashed #e63b3f; margin-top: -40px; } .weixin-form img { width: 140px; float: right; margin-top: -126px; margin-right: -3px; } .weixin-n { color: #e63b3f;
微信公众平台后台添加关键词回复即可,如题:安利一款,小姐姐推荐的BT磁力搜索软件:http://pan.defcon.cn/file/1855579-452826001
在发布内容的时候(如文章),在文章添加符合规范的标记(如,[wpkt])。在前台展示文章内容的时候,可以将正文中的标记替换成别的内容,至于替换成什么内容,由开发者所写的代码决定。
// 注册[tiezhu]短代码// 在主题的 functions.php 中添加如下代码
// 作用是将正文中的[tiezhu],替换成……<h2>wp自学笔记牛逼</h2>
function tiezhu_shortcode_handler($atts = array(), $content = null, $tag = \'\'){
$content = \'<h2>wp自学笔记牛逼</h2>\';
return $content;
}
function tiezhu_shortcode_register(){
add_shortcode(\'tiezhu\', \'tiezhu_shortcode_handler\');
}
add_action(\'init\', \'tiezhu_shortcode_register\');
当注册好短代码后,除了直接在内容的正文中使用短代码外,你可以通过以下的代码,在任何地方去使用。
<?php echo do_shortcode(\'[tiezhu]\'); ?>
Demand feedback