0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

WordPressで会員サイトを作る際に
ログインの有無で表示を変える必要があったので
ショートコードを作って対応したのでその記録です。

実際のコード

ログインしているユーザーは見られる

functions.php
function display_login($atts, $content = null) {
  // ユーザーがログインしている場合は、コンテンツを表示
  if (is_user_logged_in()) {
    return do_shortcode($content);
  } else {
  }
}
add_shortcode('login', 'display_login');

ログインしていないユーザーは見られる

functions.php
function display_no_login($atts, $content = null) {
  // ユーザーがログインしていない場合は、コンテンツを表示
  if (!is_user_logged_in()) {
    return do_shortcode($content);
  } else {
  }
}
add_shortcode('no_login', 'display_no_login');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?