WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. sixfootjames
    Member
    Posted 1 year 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;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.