サポート » プラグイン » プラグインInsertPHPを使ってのリダイレクトができない

  • 皆様のお知恵をお貸しください。

    InsertPHPを使って、ログイン状態で1つの固定ページを開くと、
    そのページからホームにリダイレクトされるようにしたいのですが、リダイレクトされません。

    [insert_php]
    if ( is_user_logged_in() ) {
    echo ‘既にログイン済みです’ ;
    wp_redirect( home_url() );
    }
    [/insert_php]

    以上のように書きました。どうしてリダイレクトされないのか分かりません。

    どうかアドバイスをお願いします。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • プラグインinsertPHPのFAQに、リダイレクトはできないと明記してありますよ。

    Why can’t I set cookies or do a browser redirect?
    With PHP, cookies are set in the web page header lines, before any page content is processed. Redirects, too, are done in the header lines. When PHP code is within a post or a page, all the header lines have already been sent, along with part of the content. At that point, it is too late to set cookies or redirect with PHP.

    トピック投稿者 Umeno

    (@daisukem)

    gblsm様

    ご回答ありがとうございます。FAQに目を通しておくべきでした。
    気付かせてくださってありがとうございます。

    プラグインを使わずにフック(アクション)を使う方法なら下記が参考になると思います。
    フォーラム » テーマ内でのリダイレクト方法について

    トピック投稿者 Umeno

    (@daisukem)

    @gblsm 様フックを使ってやってみます。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • トピック「プラグインInsertPHPを使ってのリダイレクトができない」には新たに返信することはできません。