WordPressでユーザー画面のみメンテナンス表示するする方法

実装サンプル

functions.php

functions.phpに下記記述を追加します。

function maintenance_mode() {
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
header('Location: メンテナンスページURL');
exit();
}
}
add_action('get_header', 'maintenance_mode');

maintenance.html

メンテナンスページにはメンテナンス対象のサイト名とメンテナンス期間、また簡単なメッセージがあるとよいかと思います。

下記サンプルのHTMLコードとなります。

<!DOCTYPE html>
<html>

<head>
  <meta name="robots" content="noindex,nofollow" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
  <meta charset="utf-8">
  <title>(サイト名) メンテナンスのお知らせ</title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <style><!--
  body { text-align:center; padding:50px 0; color:#444; }
  p { margin-bottom:25px; }
  .period { background:#eee; margin:15px auto 40px auto; padding:15px 30px; border-radius:8px; max-width:500px; font-size:18px; }
  .period p span { font-size:16px; display:block; margin-bottom:10px; }
  footer {
    margin:50px 0;
  }
  address { font-style:normal; }
  --></style>
</head>

<body>

  <header id="new-header-pc">
    (サイト名)
  </header>

  <div id="container">

    <div class="period">
      <p>
        <span>【メンテナンス日時】</span>
        ○○月○○日(土)○○:○○ ~ ○○:○○
      </p>
    </div>

    <p>
      只(サイト名)のWebサイトをご利用いただけません。
      <br />
      メンテナンス終了までしばらくお待ちください。
    </p>

    <p>
      ※作業の状況により、終了時刻が伸びる場合がございます。予めご了承をお願いいたします。
    </p>

  </div>

  <footer>
    <address>
      Copyright © (サイト名). All Rights Reserved.
    </address>
  </footer>

</body>

</html>