Forums

Redirect a user from a certain page if they are not logged in. (1 post)

  1. sixfootjames
    Member
    Posted 4 months ago #

    Hi,

    I would like to know how I can redirect a user from a certain page if they are not logged please? I have a "profile page" that nobody should be able to access if they are not logged into WordPress.

    Never mind...as I was typing this I tried a few things and this seems to work on the template I am using.

    <?php
    /*
    Template Name: Profile Page
    */
    
    // check if user logged in
    if ( is_user_logged_in() ) {
        echo '';
    } else {
        wp_redirect( home_url() );
        exit;
    }
    ?>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.