WordPress Custom Menu Widget Style

Purely with CSS you could set a width for menu items, float them and then set the UL to twice that: footer ul { width: 200px; } footer .menu-item { float: left; width: 100px } (I don’t know what elements you are using to designate your footer, you’ll need to update that to match your … Read more

how to get nav menu list through menu name in wordpress

I think you’re looking for the wp_nav_menu() function, which deals with the navigation menus that you create in the WordPress admin (Appearance > Menus) You can call it like this: <?php wp_nav_menu( array( ‘menu’ => ‘Header Menu’ ) ); ?> Where Header Menu is the name of the menu you want to print. There are … Read more

wordpress custom post type remove duplicate menu item

Just added ‘all_items’ => __( ” ), in labels array. Replace your code with below code register_post_type(‘news’, array( ‘labels’ => array( ‘name’ => __( ‘News’), ‘singular_name’ => __( ‘News’), ‘add_new’ => _x( ‘Add New News’, ‘News’), ‘add_new_item’ => __( ‘Add New News’), ‘edit_item’ => __( ‘Edit News’), ‘new_item’ => __( ‘New News’), ‘view_item’ => __( … Read more

Add class to active element and its parent in nav menu

Depending on the context you need this and working off of the code you have, you can try this: add_filter(‘nav_menu_css_class’, ‘add_active_class’, 10, 2 ); function add_active_class($classes, $item) { $class_names = array( ‘current-menu-item’, ‘current-menu-ancestor’, ‘current-menu-parent’, ‘current_page_parent’, ‘current_page_ancestor’ ); if( $item->menu_item_parent == 0 && in_array( $class_names, $classes) ) { $classes[] = “active”; } return $classes; } UPDATE: … Read more

Remove all nav menu classes ( but keep useful ones… )

You could work with a white-list and replace the regular expression with something more readable: add_filter( ‘nav_menu_css_class’, function( $classes ) { $allowed = [ ‘menu-item-has-children’, ‘current-menu-item’ ]; return array_intersect( $classes, $allowed ); }); That would make it easier to maintain the white-list too.

How to make menu items active based on hash

This can be accomplised fairly easy by checking the URL then setting the appropriate link to active. That can be accomplished by the following… var hash = window.location.hash.substr(1); // Get the text after the hash $(‘a[href=”#’ + hash + ‘”]’).addClass(‘active’); // Set the correct link to active However, there are some things to consider. Someone … Read more

wp_nav_menu – page template name as item class

The nav_menu_css_class filter will let you add CSS classes to specific menu items. We combine that with the get_page_template_slug function to fetch the page template filename, then we use that with the get_page_templates method of the theme class to get the template name as defined in the Template Name: header. Then we pass that result … Read more