Reply To: Log in

Home Forums Community & News Log in Reply To: Log in

#1202
ptHarry
Participant
    • 106
    • Power Poster
    @patreon_96291032
    Like
    Up
    1
    ::

    Not quite, because there’s nowhere to put the code within the menu itself. But it seems to be possible by a slightly different method (which I have working on a dummy site at https://bbp.opnsrcevents.com with user=testUser and password=testPass).

    So what I did there was to add two links (one for Login as Member with a css class of linkLogin, one for Logout with class of linkLogout) to the menu and then use a script outside the menu to hide the unwanted link at load time.

    Actually I used javascript, because it would have taken me a lot longer to work out how to code it in PHP. The actual code:

    <script>addEventListener(“load”, setLogLinks);

    function setLogLinks()
    {
    var isLoggedIn = document.body.classList.contains(‘logged-in’);
    document.getElementsByClassName(“linkLogin”)[0].style.display = isLoggedIn ? “none” : “flex”;
    document.getElementsByClassName(“linkLogout”)[0].style.display = isLoggedIn ? “flex” : “none”;
    }
    </script>

    I found a plugin WPcode which allows javascript (or PHP) to be embedded in various places of the web page. It adds a header and footer link on the WP dashboard and the code is best put in the header.

    If that seems useful, I’ll write it up properly on a PDF page which is less likely to mangle the code and can include screenshots.