wordpress隐藏文章的部分内容,需要注册登录网站后可见
这种方式适合VIP会员,会员要注册登录才能访问,而注册需要邀请码,可以出售邀请码,就变成了VIP会员可以访问隐藏的内容。
在主题模板函数 functions.php的<?php下边添加代码实现。
// 添加只允许登录后查看 add_shortcode( 'members_only', 'members_only_shortcode' ); function members_only_shortcode( $atts, $content = null ) { if ( is_user_logged_in() && !empty( $content ) && !is_feed() ) { return $content; } $a= '<center><span> <div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:green;">要查看更多文章内容,请您先<a href="http://www.zw1.net/wp-login.php" target="_blank">登录/注册</a> </div> </span></center>'; return $a; }
在需要加密的内容头底加入下边两段代码(html编辑器中加入),就会提示只有登录后才能访问隐藏内容,你就等着卖VIP赚大钱把。
[members_only] 这里的内容只为已登录的用户显示的 [/members_only]
效果如图: