博主用心写一篇文章很辛苦,希望输出的有价值的内容能够换回来有价值的流量。但是貌似白嫖党往往会让站长慢慢失去了写作的热情。所以很多wordpress博主希望通过博客文章为自己的微信公众号也吸引一些流量。接下来就看下如何通过wordpress文章为微信公众号吸粉。
当然,这个功能是可以通过插件来实现的,但本人是喜欢代码版的;所以直接上代码了!
1 核心代码
将以下代码放入 functions.php 中
/**
* WordPress文章部分内容关注微信公众号后可见
*/
function lxtx_secret_content($atts, $content=null){
extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
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="/wp-content/uploads/2021/08/1629948859-087214dc4b0b777.jpg" width="150" height="150" alt="迷途向导"><div class="post-secret"><i class="fa fa-exclamation-circle"></i>此处内容已经被作者无情的隐藏,请输入验证码查看内容</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>'.$keyword.'</span>”,获取验证码。</div>
</div>';
}
}
add_shortcode('gzh2v', 'lxtx_secret_content');
注意修改代码中的相关内容!
2 前端 CSS 样式
将以下代码放到你主题的 style.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]{ color: #9ba1a8; padding: 6px; background-color: #f6f6f6; border: 1px solid #e4e6e8; font-size: 12px;-moz-transition: border .25s linear,color .25s linear,background-color .25s linear; -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear; -o-transition: border .25s linear,color .25s linear,background-color .25s linear; transition: border .25s linear,color .25s linear,background-color .25s 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;}
3 集成短代码
为了方便使用,在后台文本编辑器中集成该短代码。将以下代码放入 functions.php 中即可
// 后台文本编辑框中添加公众号隐藏简码按钮
function lxtx_wpsites_add_gzh_quicktags() {
if (wp_script_is('quicktags')){
?>
<script type="text/javascript">
QTags.addButton( 'gzh2v', ' 公众号隐藏', '\n
输入验证码即可免费获取
微信扫描二维码或搜索公众号『迷途向导』,关注并回复关键字“关键字”,获取验证码。
', "" );
</script>
<?php
}
}
add_action( 'admin_print_footer_scripts', 'lxtx_wpsites_add_gzh_quicktags' );
4 使用方法
(PS:为了做个 DEMO,代码被我隐藏起来了~):
输入验证码即可免费获取
微信扫描二维码或搜索公众号『迷途向导』,关注并回复关键字“2046”,获取验证码。
依米资源网是一个免费资源平台,1米为收集整理的费用。本站所有资源均来自于互联网,版权归原作者所有,请于下载24小时之内删除,请勿商用,支持正版。
依米资源网 » wordpress纯代码实现文章部分内容关注公众号可见 超强微信公众号增粉功能
依米资源网 » wordpress纯代码实现文章部分内容关注公众号可见 超强微信公众号增粉功能
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 依米资源网