wordpress 記事にパスワードを付けURLからパスワードなしで限定公開 2020年9月1日
Tag:

事にパスワードを付けURLからパスワードなしで限定公開する方法

1.記事にパスワードをかけ限定公開
2.記事のURLを知っている人にのみパスワードを入力せずに表示させたい

1.functions.phpに書きをコピー

/**
 * 秘密URLからパスワードなしで読めるよう設定
 **/
function custom_smart_password_form($html) {
  global $post;
  
  $password = @$_GET['post_password'];
  
  if ( isset($password) ){
    /// パスワード付きURLの場合...
    /// 自動閲覧できるようにする
    $html .= <<<EOM
<script>
window.addEventListener("DOMContentLoaded", function(){
  jQuery('[name="post_password"').val('{$password}');
  setTimeout(function(){
    var urlBeforeQuery= location.href.split("?")[0];
    window.history.pushState({}, document.title, urlBeforeQuery );
    jQuery('[type="submit"]')[0].click();
  }, 100);
});
</script>
EOM;
  }
  
  return $html;
}
add_filter( 'the_password_form', 'custom_smart_password_form' );

2.記事の公開設定をパスワード保護にする

3.パスワードの入力を省くURLを記載

例:https://msweb.sakura.ne.jp/works?post_password=1235

1.ページのURLが https://msweb.sakura.ne.jp/works
2.URLの後ろに ?post_password=1235 を追加
password=1235 ← 1235部分がパスワード

New

Aechive

Tag

css Facebook facebookカスタマイズ Facebookページ font functions.php google NEWマーク RSS single.php webツール WEBデザインツール Wordpress アーカイブ カスタム カスタムフィールド カスタムフィールドテンプレート カスタム投稿 カテゴリー カレンダー サイドバー ターム テキスト テンプレートタグ プラグイン ヘッダ ページ ポップアップ メニュー 並び替え 並べ替え 人気 便利 分岐 印刷 年別アーカイブ 投稿 投稿記事 改行 文字数 文法チェック 最新記事 月別アーカイブ 特定カテゴリー 画像