Jump to content

Theme_Location of Simple Nav Section

Recommended Posts


I'm trying to add a login/logout conditional to my Standard NavBar.


I've created the menu via WP's menu system (though the menu showed just fine before I did that). Anyway, I've named the menu 'Main' and added it to the Simple Nav Section theme location. This seems to work fine, but loses my footer info though.


Then I added the following to my base functions file:

add_filter('wp_nav_menu_items','my_login_func', 10, 2);
function my_login_func($nav, $args) {
          $loginoutlink = ob_get_contents();
          if( $args->theme_location == 'main' ) {
                  $nav .= ''. $loginoutlink .'';
          return $nav;

No login/out menu item shows and it throws a LESS compile error on the theme_location == 'main'.

parse error: failed at `if( $args->theme_location == 'main' ) { ` line: 1104

I've tried various names for the menu (simplistic, I know), to no avail.

Using dev tools in Safari and also in Chrome does not show me what I need to reference (simple_nav, simple_nav_section, etc.).

I think I'm approaching this incorrectly but have reached a dead end.


May I have a hint please?  :pic:


Due to the footer issue I've removed the wp menu allocation for now and am relying on PL's NavBar.

Share this post

Link to post
Share on other sites

Hi Dario,


I suspect this isn't going to be the easiest thing, and since I'm not a programmer, I wouldn't venture a guess about your code.  Obviously something, somewhere doesn't seem to agree with it.   The footer, being a unique section is probably missing a conditional that says that the login is for the whole site... so if you are successful in the Nav Classic, you're being logged in within the section, probably .content or some other element, but then the footer isn't tagging along for the ride. So as far as Simple Nav is concerned, no one has logged in via that menu, thus you can't see the footer. That being a coding problem, PageLines throws you a little error.


Forgive my simple perspective on this, but I think your prime goal is simply to make login to the site easy, simple and accessible to your visitors.  To do that, placing a login link in the menu usually works, but most people would simply make the link, rather than creating custom code. I see your point tho, and suggest, instead, using SideBar Login, a well-established, well-maintained plugin you can place anywhere that a sidebar goes.


I know this isn't the most ideal scenario, and definitely not what you'd like, but short of hiring a custom programmer, it's the fastest and easiest method. You could place the widget at the top of your primary sidebar, and if you were using the multi-column footer sidebar, you could add it to the footer.


Let me know if you need additional help with this.

Former PageLines Moderator, Food Expert and Raconteur

Share this post

Link to post
Share on other sites

Interesting Rob. I'm holding onto your suggestions as a fallback in case nobody else comes up with a direct solution. I did the widget route for awhile but would prefer it in the menu. I'm not allowing users access to the WP dashboard/admin menu but they do need a logout.


Perhaps I should try what I'm attempting on a standard theme (2011 or another), just to rule out a PL issue. Not that it's a PL issue directly, rather, probably something I don't understand about how PL calls the page elements. The footer disappearing act shows my ignorance of that. I can almost always hack my way around but it would be nice to do things properly.


I still think that all I'm missing is the proper argument for the theme_location or the proper hook for the filter. One in the same perhaps?

Share this post

Link to post
Share on other sites

Honestly,  I'm not sure.  I suspect there's a few missing conditionals as well.


Are you familiar with the Dashboard access level settings in PageLines? They're located at the bottom of Dashboard > PageLines > Site Options > Advanced. You'd use these to control who has access to different dashboard tabs.  There are also plugins that let you control which access levels use the different Dashboard components at different levels.


Also, have you tried s2Member plugin? I've used it with no problems (for membership management) and it integrates perfectly with PageLines. That might have some options for you.

Former PageLines Moderator, Food Expert and Raconteur

Share this post

Link to post
Share on other sites



Check out this article - it might point you in the right direction. It uses another method than what you posted here. You would have to find a way to incorporate the theme location AND/OR the specific menu class/id.




The location of the menu is given in your-child-theme-folder/sections/simple_nav/section.php. 

function section_template() { 

		wp_nav_menu( array('menu_class'  => 'inline-list simplenav font-sub', 'theme_location'=>'simple_nav','depth' => 1,  'fallback_cb'=>'simple_nav_fallback') );


so: theme_location is simple_nav. 


Happy coding & good luck!

Share this post

Link to post
Share on other sites

Thanks to you both.



Yes to the Dashboard access level settings in PageLines and yes to the s2Member plugin. I removed it awhile back though (for a long forgotten reason) but I'll give it another look.



The simple_nav appears in my footer and I've had no luck targeting that, other than having it disappear. I 'think' the theme_location for the NavBar is 'main-nav' but I'm not having luck with that either.


I did, however, just succeed with the following. The source of the code is here and here.

What I had to do was create a regular wp menu, add the items I wanted to it and then attach it to the Primary Website Navigation theme location drop down.

That resulted in my main navigation bar functioning just like it did when all I was using was the PL fixed NavBar.

Then I added the following to the base theme's functions.php file:

if ( !class_exists('JMO_Custom_Nav')) {
    class JMO_Custom_Nav {
        public function add_nav_menu_meta_boxes() {
        		__('WishList Login'),
        		array( $this, 'nav_menu_link'),
        public function nav_menu_link() {?>
        	<div id="posttype-wl-login" class="posttypediv">
        		<div id="tabs-panel-wishlist-login" class="tabs-panel tabs-panel-active">
        			<ul id ="wishlist-login-checklist" class="categorychecklist form-no-clear">
        					<label class="menu-item-title">
        						<input type="checkbox" class="menu-item-checkbox" name="menu-item[-1][menu-item-object-id]" value="-1"> Login/Logout Link
        					<input type="hidden" class="menu-item-type" name="menu-item[-1][menu-item-type]" value="custom">
        					<input type="hidden" class="menu-item-title" name="menu-item[-1][menu-item-title]" value="Login">
        					<input type="hidden" class="menu-item-url" name="menu-item[-1][menu-item-url]" value="<?php bloginfo('wpurl'); ?>/wp-login.php">
        					<input type="hidden" class="menu-item-classes" name="menu-item[-1][menu-item-classes]" value="wl-login-pop">
        		<p class="button-controls">
        			<span class="list-controls">
        				<a href="/wordpress/wp-admin/nav-menus.php?page-tab=all&amp;selectall=1#posttype-page" class="select-all">Select All</a>
        			<span class="add-to-menu">
        				<input type="submit" class="button-secondary submit-add-to-menu right" value="Add to Menu" name="add-post-type-menu-item" id="submit-posttype-wl-login">
        				<span class="spinner"></span>
        <?php }

$custom_nav = new JMO_Custom_Nav;

add_action('admin_init', array($custom_nav, 'add_nav_menu_meta_boxes'));

That code added a custom meta box to the WordPress navigation menu interface on the admin-side.

I added the new menu item (WishList Login/Logout link), created by the code above, to the menu.

I then had to allow CSS Classes in the Screen Options > Show Advanced Menu Properties slide down.


Then I added the following code to the bottom of the base theme's function.php file:

if ( !class_exists( 'HijackMe' ) ) {
    class HijackMe {
        public function hijack_menu($objects) {
		 * If user isn't logged in, we return the link as normal
		if ( !is_user_logged_in() ) {
			return $objects;
		 * If they are logged in, we search through the objects for items with the 
		 * class wl-login-pop and we change the text and url into a logout link
		foreach ( $objects as $k=>$object ) {
			if ( in_array( 'wl-login-pop', $object->classes ) ) {
				$objects[$k]->title = 'Logout';
				$objects[$k]->url = wp_logout_url();
				$remove_key = array_search( 'wl-login-pop', $object->classes );

		return $objects;

$hijackme = new HijackMe;

add_filter('wp_nav_menu_objects', array($hijackme, 'hijack_menu'), 10, 2);

This works great. Along with the Restricted Site Access plugin I have the site set to redirect to the login page upon the user logging out.

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now