Forums

Login/logout in Non WordPress Pages (4 posts)

  1. borisz
    Member
    Posted 1 year ago #

    Hi all,

    Im looking for advice on how to make login and logout wordpress link work on non wordpress pages. I have already included:

    <?php
    require('blog/wp-blog-header.php');
    ?>

    and when I add:

    <?php wp_loginout(); ?>

    or

    <?php
    if ( is_user_logged_in() ) {
        echo 'Welcome, registered user!';
    } else {
        echo 'Welcome, visitor!';
    };
    ?>

    it seems like it does not recognize that Im loged in wordpress. Any idea what other SP files I also should include so this thing work?

    Thanks!

  2. doodlebee
    Member
    Posted 1 year ago #

    your require statement requires the correct path to wp-blog-header.php. You will also want to make the the FULL SERVER PATH on every page you plan to pull in from WordPress, since outside of WordPress, you'll be changing directories all the time, and a relative location will pull in the wrong URL.

    BTW a server path doesn't begin with http:// - that's the URL. You need to find out from your host what the server path is (starts with something like "usr/site/public_html/...")

    If you're only doing it for one single page (like a welcome page) then you can use the path relative to where that page is. So if your welcome page is at the root, then your path should be './blog/wp-blog-header.php'. However, it would probably just be much simpler to put the WordPress install in the root of your site, and set a Page as the home page. Then you don't have to go through all of this.

  3. borisz
    Member
    Posted 1 year ago #

    thanks for the reply doodlebee,

    the path to wp-blog-header.php is ok. I just dont know why when I login into wordpress and visit this page where I added this code, it does not recognize Im logged it. Again this page is outside WP installation folder and is not part of WP. When I added any other code e.g. latest WP posts it does work OK but login/logout dont work very well, could it be because of cookies or something else?

    Thanks!

  4. doodlebee
    Member
    Posted 1 year ago #

    Well, the page you're logged into is outside of WordPress, so probably, yeah, it wouldn't recognize it. I do believe WP uses cookies, but I'm not 100% sure of that. I know you can use the blog-header file to pull in the theme files and use the template outside of WordPress, but I don't believe anything else works - like plugins I dont' think would.

    You'd probably - again - be better off just creating a Page in your WP install and using the password protection there.

    Or, another idea - don't know if this'll work - but you might want to use "get_current_user" stuf to see if it recognizes you, and if it does, just set it so the user level you desire will see the content or not. (That could also work within WP - probably more reliably. Just edit the theme file for that particular Page.)

    I guess the question is, why don't you want to use WP to manage the page in question?

Topic Closed

This topic has been closed to new replies.

About this Topic