Custom Menus, Widgets & Conditional Statements

if you want to show the menus only on child pages then you need to change your conditional statement: global $post; //only on children of 269 if (‘269’ == $post->post_parent){ //menu for Sport & Fitness pages ?> <div id=”seventh” class=”widget-area” role=”complementary”> <?php dynamic_sidebar( ‘sidebar-7’ ); ?> </div><!– #second .widget-area –> <?php //only on children of … Read more

Automatically generated menu

Yes! Yes it can, you will need to hook into the filter used by the walker, e.g.: add_filter( ‘walker_nav_menu_start_el’, ‘menu_show_project_post’, 10, 4 ); function menu_show_project_post( $item_output=””, $item = ”, $depth=””, $args=”” ) { global $post; if ( is_array( $item->classes ) ) { $query = false; foreach( $item->classes as $class ) { if ( $class == … Read more

Why do the menu titles change with the renaming of pages?

Are you in Appearance > Menus? Is that what you mean by custom menu? Can you share the code you are using to make the menu display? I have this in my header: wp_nav_menu( array(‘menu’ => ‘topnav’ )); Where topnav is the name of my custom menu. You have to add the pages to the … Read more

Adding a ‘mega menu’ to my site without a plugin

I’ll just point out how you can insert the HTML of your mega dropdown menu, then it’s up to you to style and animate it. Dig around in wp-includes/nav-menu-template.php to find different useful filters for modifying navigation menus created in the admin area. I chose for the walker_nav_menu_start_el filter which gets applied to each menu … Read more

Add Submenu Link in add_submenu_page That Opens in a New Window

This has to be solved: with an unconventional submenu manipulation, provided by @t31os in this Answer and some jQuery add_action( ‘admin_menu’, ‘wpse_66020_admin_menu_new_item’ ); add_action( ‘admin_head’, ‘wpse_66020_add_jquery’ ); function wpse_66020_admin_menu_new_item() { global $submenu; $submenu[‘index.php’][500] = array( ‘<div id=”wpse-66020″>Go to WPSE</div>’ , ‘manage_options’ , ‘https://wordpress.stackexchange.com/’ ); } function wpse_66020_add_jquery() { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $(‘#wpse-66020’).parent().attr(‘target’,’_blank’); … Read more

display only the wp_nav_menu, which has the current-menu-item

Just intercept the nav classes and search for the current-menu-item class. This will give you the $item it’s associated with. add_filter( ‘nav_menu_css_class’, ‘get_active_class’, 10, 2 ); function get_active_class( $classes, $item ) { if ( in_array( ‘current-menu-item’, $classes) ) { // We found the active class!: $item } return $classes; } Now just grab your nav … Read more

Add nav menu CSS class to body

This is what I managed to cobble together thanks to Mridul Aggarwal’s hints: function pa_assign_menu_class_to_body(){ // ‘main’ is the theme_location, set earlier using register_nav_menus() $menu_name=”main”; $class_list = array(); if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menu_items = wp_get_nav_menu_items($menu->term_id); // _wp_menu_item_classes_by_context() … Read more

Custom Nav Walker to show siblings and children of current branch?

Well, as much as I prefer to have my own walker and control over the nav, I found a plugin that does exactly what I want: Advanced Menu Widget http://wordpress.org/extend/plugins/advanced-menu-widget/ Only tested slightly but its working just as I expected, just have to select “Only strictly related sub-menu” in the menu widget config. I should … Read more