Tag Archives: menu

display menu item only for registered user

functions.php

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'.get_permalink(74939).'">Documents</a></li>';
}
return $items;
}

Show or Hide Menu item for specific page or users

/*Show/Hide Menu item for specific page or users */
and also you can manage menu order by ietm


add_filter( 'wp_nav_menu_objects', 'custom_menu_item', 10, 2 );
function custom_menu_item ( $items, $args ) {

$new_links = array();
$className[] = array();
$className[] = 'menu-item';
if(is_user_logged_in())
{
// only if user is logged-in, do sub-menu link
$item = array(
'title'            => 'Training room',
'ID'               => 'menu-item-74773', // Add page id
'db_id'            => 'custom',
'url'              => get_permalink(74773), //Add Page ID
'classes'          => $className
);
}
$new_links[] = (object) $item;  // Add the new menu item to our array
unset( $item ); // in case we add more items below

$index = count( $items );  // integer, the order number.

array_splice( $items, 12, 0, $new_links ); // Set order of your menu item
return $items;
}

Register and display menu

function.php
register_nav_menu( ‘footer’, __( ‘Footer Menu’, ‘gshop’ ) );

footer.php
<?php  wp_nav_menu( array(‘theme_location’ => ‘footer’));    ?>

Child pages of parent page menu in sidebar

You can also use this plugin:
http://wordpress.org/plugins/child-page-navigation/
if u want add main title as main page then use this plugin:
https://wordpress.org/plugins/children-pages/screenshots/
by default all childpages short by name, if u want add desiding order then:
got to plugin’s => edit => and replace this line
$pages = wp_list_pages(‘depth=0&title_li=&child_of=’.$id.’&echo=0&sort_column=menu_order’);

past in sidebar.php 

<?php global $post;?>
<?php
if($post->post_parent){
$parent_title = get_the_title($post->post_parent);
$children = wp_list_pages(“depth=1&title_li=&child_of=”.$post->post_parent.”&echo=0″); // append the list of children pages to the same $children variable
}
if ($parent_title) { ?>
<h2 class=”widgettitle”><?php echo $parent_title; ?></h2>
<?php }

if ($children) { ?>
<ul class=”submenu”>
<li><?php echo $children; /*print list of pages*/ ?></li>
</ul>
<?php } ?>

%d bloggers like this: