利用短代码实现会员登录可见内容

将下面的代码添加到主题functions.php模板文件中: function member_check_sh…

将下面的代码添加到主题functions.php模板文件中:

  1. function member_check_shortcode($atts$content = null) {
  2.      if (is_user_logged_in() && !is_null($content) && !is_feed()) {
  3.           return do_shortcode($content);
  4.      }
  5.      return ‘<p>请注册登录后查看内容</p>’;
  6. }
  7. add_shortcode(‘member’, ‘member_check_shortcode’);

然后在编辑文章是可以通过添加短代码,只有登录用户才能看到的内容

  1. [member]登录后显示的内容[/member]

原文:http://wp-mix.com/members-only-content-shortcode/

类别:WordPress入门

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT

登录 账号发表你的看法,还没有账号?立即免费 注册