latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Hide the Log In Link in a menu

Home Forums Community Forum Hide the Log In Link in a menu

This topic contains 10 replies, has 3 voices. Last updated by  Mike Lowndes 4 years, 2 months ago.

Topic Author Topic
Posted: Friday Oct 19th, 2012 at 9:48 am #29004

Hi All,

i want to add a link in the menu for users to LOG IN to the membership site – This is easy and i’ve added a menu link to the page.

BUT

If a user has LOGGED IN i want to hide this link

Displaying a LOG IN link when a user has logged in will be confusing

Can you help?

List Of Topic Replies

Viewing 10 replies - 1 through 10 (of 10 total)
Author Replies
Author Replies
Posted: Friday Oct 19th, 2012 at 10:07 am #29013

Hi Mike,

maybe you can set up two menus.

One for visitors and the other one for members.

<?php
if ( is_user_logged_in() ) {
   wp_nav_menu( array( 'theme_location' => 'members' ) );
} else {
   wp_nav_menu( array( 'theme_location' => 'visitors' ) );
}
?>

You can put that code in your theme header.php file where the old menu is.

hope it helps

Posted: Friday Oct 19th, 2012 at 10:12 am #29016

Good thinking Christian, I’ll give it a try and let you know

Posted: Friday Oct 19th, 2012 at 10:16 am #29018

me again, :)

on wordpress codex site is a complete guide. here

Register Menus

Firstly, in your theme’s functions.php, you need to write a function to register the names of your menus. (This is how they will appear in the Appearance -> Menus admin screen.) As an example, this menu would appear in the “Theme Locations” box as “Header Menu”.

function register_my_menus() {
  register_nav_menus(
    array( 'header-menu' => __( 'Header Menu' ) )
  );
}
add_action( 'init', 'register_my_menus' );

And this would make two menu options appear, header menu and extra menu

function register_my_menus() {
  register_nav_menus(
    array(
      'header-menu' => __( 'Header Menu' ),
      'extra-menu' => __( 'Extra Menu' )
    )
  );
}
add_action( 'init', 'register_my_menus' );

Display Menus on Theme

<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>

additional information have a look at: http://codex.wordpress.org/Navigation_Menus

try it it’s not so hard :)

Posted: Friday Oct 19th, 2012 at 11:28 am #29034

ooops,

i think i found something you may looking for on the codex wordpress site

Description
Displays a login link, or if a user is logged in, displays a logout link. An optional, redirect argument can be used to redirect the user upon login or logout.

Usage

<?php wp_loginout( $redirect, $echo ); ?> 

Parameters
$redirect
(string) (optional) URL to redirect to on login/logout. This parameter is available since Version 2.8.
Default: None
$echo
(boolean) (optional) If true, echos the link, if false, returns the link as a string.
Default: true

Example

<p><?php wp_loginout(); ?></p>

really simple

Posted: Friday Oct 19th, 2012 at 11:35 am #29036

You’re a start thank you.

Just one question – I’m no programmer – more of a cut and shunt coder – How would i use this code?

Thanks for all your help

Mike

Posted: Friday Oct 19th, 2012 at 6:07 pm #29078

Hi again,

you can just put this snippet in your theme where you wish to display that “Log in | Log Out” function.

If you want it in your header next to the menu (perhaps)

Just have a look in your theme folder for the file “header.php” -> edit this file by inserting this peace of code

<?php wp_loginout(); ?>

In the default theme (twenty eleven) for example
showing only the lines 128 to 136 from “header.php”

128. <nav id="access" role="navigation">
129. <h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
130. <?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
131. <div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
132. <div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
133. <?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assigned to the primary location is the one used. If one isn't assigned, the menu with the lowest ID is used. */ ?>
134. <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
135. </nav><!-- #access -->
136. </header><!-- #branding -->

you can paste it between 134-135

...
134. <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
134.5 <!-- here --><?php wp_loginout(); ?><!-- here -->
135. </nav><!-- #access -->
136. </header><!-- #branding -->
...

hope it helps

Posted: Monday Oct 22nd, 2012 at 5:44 am #29234

Thanks Christian – that’s fixed it nicely – ive just got to figure out how the format it the same as the other menu items now. If you have any suggestions feel free.

here’s the shell site http://networkmarketingsystem.mikelowndes.com

Posted: Monday Oct 22nd, 2012 at 12:55 pm #29278

Hi Mike,

as i could see the css needs to be fixed.

take a look at the screenshot i made

your code need to be inside the div command.

<div class="menu-main-navigation-container">
<ul id="menu-main-navigation" class="menu">
<li id="menu-item-64" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-20 current_page_item menu-item-64"><a href="http://networkmarketingsystem.mikelowndes.com/">Home Page</a></li>
</ul>
<ul id="menu-main-navigator-container">
<li class="menu" id="menu-item-64">
<a href="http://networkmarketingsystem.mikelowndes.com/wp-login.php">Log in</a></li>
</ul>
</div>

that was quick and dirty google chrome html editing :-)

<ul id="menu-main-navigator-container">
<li class="menu" id="menu-item"><?php wp_loginout(); ?></li>
</ul>

hope that will help you

Posted: Tuesday Oct 23rd, 2012 at 5:31 am #29363
[note_box]
Christian, I gave you the “Helpful User” badge. Thanks! :)
[/note_box]
Posted: Tuesday Oct 23rd, 2012 at 5:50 am #29366

Christian – Thank you – that worked perfectly and all is ready for the new theme… :-)

Viewing 10 replies - 1 through 10 (of 10 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.