Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
128 votes
7 answers
108k views

add_menu_page() with different name for first submenu item

The add_menu_page documentation says to pass the menu title as the second parameter: add_menu_page('Page Title', 'Menu Title', ...); When adding more pages later via add_submenu_page, the main page ...
MegaHit's user avatar
  • 1,553
113 votes
11 answers
48k views

Display a portion/ branch of the menu tree using wp_nav_menu()

I have a menu defined in WP Admin that looks like this: I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" ...
jessegavin's user avatar
  • 3,466
111 votes
4 answers
113k views

Menu items description? Custom Walker for wp_nav_menu()

Normal Wordpress Menu looks like: Home | Blog | About us | Contact But I've seen many pages with descriptions under these links: Home Page | Our Blogs | About us | Contact ...
Wordpressor's user avatar
  • 5,051
52 votes
2 answers
64k views

Any docs for wp_nav_menu's "items_wrap" argument?

I'm using wp_nav_menu and am trying to create custom output for the sub-level drop downs. I came across the "items_wrap" argument but there's really not much information as to what it is, how it ...
RodeoRamsey's user avatar
  • 1,707
51 votes
4 answers
58k views

Programmatically add a Navigation menu and menu items

Through API functions, I want to define a new Navigation menu, select it in the current theme, and then insert a few Pages as menu items. This is to be done for instance on a theme activation. ...
julien_c's user avatar
  • 891
46 votes
2 answers
76k views

Adding a Custom Post Type into the menu screen

I need a way of adding custom post types to the "Appearance-->Menus" option in Wordpress. i have created a custom post type with: register_post_type('produksjoner',$args); All examples I find just ...
Ole Henrik Skogstrøm's user avatar
45 votes
2 answers
36k views

How to add a custom field in the advanced menu properties?

Is it possible to add a custom field to menu items? What I want to do is be able to add a field for 'French Navigation Label' and a 'French Title Attribute' in the wp menu interface.
cbaigorri's user avatar
  • 822
43 votes
2 answers
53k views

Customizing Only a Specific Menu using the "wp_nav_menu_items" Hook?

Thanks to some help on here, I've managed to add a custom search box to my main menu... by adding this to my theme's functions.php add_filter('wp_nav_menu_items','search_box_function'); function ...
cannyboy's user avatar
  • 1,033
36 votes
18 answers
228k views

How make top level menu item not have link, but have sub-menus that are linked?

I'm building a horizontal menu and some of the entries on that menu will have dropdowns (sub-menus), and some won't. Those that have sub-menus are not actually pages. They're just meant to be guides ...
PVA's user avatar
  • 669
32 votes
7 answers
31k views

Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?

(Moderators note: Was originally titled "wp_nav_menu Ancestor class without children in navigation structure") I have a wp_nav_menu in my header which had three pages in it. When I am on one of those ...
Gavin's user avatar
  • 537
30 votes
6 answers
40k views

Changing the Order of Admin Menu Sections?

I am getting a bit frustrated over here after having spent a few hours trying to accomplish this fairly simple task without any luck. Essentially I have 5 custom post types which I created and all I ...
Binarybit's user avatar
  • 403
29 votes
1 answer
44k views

How to add posts to custom menus?

I'm just beginning to work the "Custom Menu" functionality that was introduced in 3.0 into my theme. I like everything about this new capability and API, with one exception: Why no posts? I can ...
Scott B's user avatar
  • 5,696
26 votes
10 answers
37k views

Placing a Custom Post Type Menu Above the Posts Menu Using menu_position?

I just figured out the menu_position parameter it seems like you can place the menu of your custom post type almost everywhere. Except above the Posts menu! How can I accomplish that?
wyc's user avatar
  • 3,897
24 votes
8 answers
48k views

Get WP Navigation Menu from REST API V2

I'm trying to get the navigation menu from JSON response using WP REST API v2 plugin. There is no navigation menu plugin extension for the REST API v2, but only for V1. From codex WordPress Post ...
Murhaf Sousli's user avatar
24 votes
4 answers
39k views

Add 'has_children' class to parent li when modifying Walker_Nav_Menu

I'm writing a customised walker class for wp_nav_menu and want to be able to specify if an li contains a submenu. So I want my markup to be: <li class="has_children [other-wordpress-classes]"> ...
patnz's user avatar
  • 1,459
23 votes
7 answers
54k views

How do I remove UL on wp_nav_menu?

I search on this site and found many answers for this question. Most of them is not working on my theme. Here is a one solution I found and it's working according to my need. function ...
haha's user avatar
  • 839
23 votes
4 answers
44k views

How to Hard Code Custom menu items

Is there any way that i can hard code the custom menu items when first theme installed? I am creating a theme which will automatically make some common pages when installed. So I need to know if I can ...
Sisir's user avatar
  • 7,821
23 votes
5 answers
79k views

How to add a Custom Link to a Menu with a URL that is relative to the blog URL

Part of my work is to create Wordpress websites. I usually work on my laptop until I have something good enough to be uploaded to the test server where the client reviews it. I create a VirtualHost ...
Willington Vega's user avatar
22 votes
4 answers
118k views

Retrieving a list of menu items in an array

I am currently am working on a custom theme. In this theme, I have a menu that I registered using register-nav-menu, and then I am displaying the menu to my web page using the wp_nav_menu function. ...
Greeso's user avatar
  • 2,204
22 votes
6 answers
52k views

Remove wrapping div and ul from output of wp_nav_menu

I am using the new menu system of Wordpress, and here is the result of wp_nav_menu() <div class="menu-main-menu-container"> <ul id="menu-main-menu" class="menu"> <li id="menu-...
user avatar
22 votes
1 answer
64k views

Wordpress default menu in database

There are 3 menus in my wordpress(3.5) now. Main menu (default from wp) Footer menu (default from wp) Test menu Now I have kept test menu as default. Where does Wordpress store this thing? I want ...
Hiren Rathod's user avatar
22 votes
2 answers
29k views

Dynamically exclude menu items from wp_nav_menu

I tried looking for info about how to exclude/remove nav menu items from custom menus, and the only thread I found did not have any answers that were useful to me. 1. Background: I put together a ...
Marventus's user avatar
  • 323
22 votes
3 answers
53k views

How to use wp_nav_menu to create a select menu dropdown?

I'm using the following inside the wp_nav_menu function to create a select dropdown menu where each menu item is an option in the select dropdown... 'items_wrap' => '<select>%3$s</select&...
Christopher John's user avatar
21 votes
4 answers
61k views

How to add a data attribute to a WordPress menu item

I'm Twitter Bootstrap and need to add data-toggle="modal" attribute to the a tag of menu link. Upon searching most all results reference doing a walking for Twitter Bootstrap dropdown menus however ...
TechRemarker's user avatar
21 votes
3 answers
15k views

Adding an Arbitrary Link to the Admin Menu?

Is there a way to add a arbitrary hyperlink to the WordPress admin menu (I mean the menu on the left when you log into the admin dashboard)? For example, can one add a link to Google? In my ...
Tom's user avatar
  • 449
20 votes
5 answers
91k views

wp_nav_menu(), how to change <li> class?

I'm building a menu for my website. The static is looking like this: <nav> <ul id="menu"> <li class="item_1"><a href="#">Item 1</a></li> <li ...
Christian's user avatar
  • 205
18 votes
4 answers
85k views

Add "Logout" link to navigation menu

How can I add a link to the primary navigation menu with the class="right" attribute? I tried to add a static link to example.com/wp-logout.php?action=logout but that leads to a logout confirmation ...
Zach Russell's user avatar
  • 1,073
18 votes
3 answers
31k views

Error: Declaration of MyClass::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl()

I'm currently working on a WordPress site and whenever in the admin I go the Appearance > Menus page I get the following error: ErrorException: Runtime Notice: Declaration of Walker_Nav_Menu_Edit::...
Luke's user avatar
  • 591
18 votes
3 answers
34k views

Display Menu Name using wp_nav_menu

I have a custom menu that I can call just fine using wp_nav_menu. Is there a way to have the menu name displayed inside an h3 tag before the menu? Ex. <h3>My Menu Name</h3> <nav> &...
csi's user avatar
  • 377
16 votes
4 answers
8k views

Split up wp_nav_menu with custom walker

I am trying to create a Menu that shows a maximum of 5 items. If there are more items it should wrap them into another <ul> Element to create a dropdown. 5 Items or less: 6 Items or more I ...
Snowball's user avatar
  • 715
15 votes
9 answers
9k views

Adding first / last CSS classes to menus

is that possible, without javascript hacks? like this: <ul class="my_menu"> <li class="first"> ... </li> <li> ... </li> <li> ... </li> <li class"...
Alex's user avatar
  • 1,081
15 votes
7 answers
46k views

Removing container from wp_nav_menu not working

I'm converting this html menu to wordpress: <ul> <li><a href="/" class="current"><span>Home</span></a></li> <li><a href="/"><span>...
Oterox's user avatar
  • 352
15 votes
2 answers
12k views

Custom Nav walker display current menu item children, or siblings on no children

I've been messing around / searching for hours and still can't get this to work, so i'm finally giving in and asking for some help. I'm trying to write a custom walker that shows only the current ...
jchamb's user avatar
  • 311
14 votes
4 answers
13k views

Convert output of nav_menu items into a tree-like multidimensional array

Is there any way to grab the nav menu items as a multidimensional array instead of a flat array? By a tree-like structure I mean something that would preserve relationship between child and parent ...
YemSalat's user avatar
  • 459
14 votes
4 answers
21k views

wp_nav_menu: show menu only if one exists, otherwise show nothing

I'm trying to use wp_nav_menu to only display a menu if one exists, otherwise, display nothing. If I delete the menu, it will output a list of the pages. My functions.php file contains: if (...
Ryan's user avatar
  • 515
14 votes
3 answers
2k views

Is there an easy way to replace a custom menu link with a page or post?

I've looked for plugins and couldn't find anything and I believe this should be a core feature. The Problem: The current methodology for replacing a custom link, or any menu link is by doing the ...
Aziz's user avatar
  • 235
13 votes
2 answers
76k views

How to modify navigation menu of the "My Account" page in WooCommerce

I want to modify the WooCommerce "My Account" left side navigation menu. For that, I have made changes in the woocommerce/templates/myaccount/navigation.php. The problems with this approach are: I ...
Dhruvang Gajjar's user avatar
13 votes
4 answers
10k views

Apply the_title() filter in post & page title, but not in menu title

I use the following code to change the title of WordPress posts and pages. But it changes nav menu item titles too, which I want to avoid. I want to change the title of posts and pages in: home page, ...
Ranuka's user avatar
  • 1,794
13 votes
2 answers
11k views

Get page IDs from nav items

I am trying to get all the IDs in my navigation and convert it to a string so that I can use it with wp_query to get the pages that are only listed in the nav. The code to get the IDs: $menu_name = '...
Jamie's user avatar
  • 1,363
13 votes
2 answers
23k views

How to add sub-menu to a menu generated by wp_nav_menu by using plugin

I have a menu generated by wp_nav_menu which look like <ul class="nav-menu" id="menu-top-nav"> <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-43" id="menu-...
Tahir Yasin's user avatar
12 votes
1 answer
14k views

Adding a menu item for a Custom Post Archive

I've created a Custom Post type (project) and it works perfectly. I have a custom archive page (archive-project.php), and that works great, too, but what's the best way to add a link to that custom ...
Django Reinhardt's user avatar
12 votes
1 answer
5k views

Check if add_menu_page exists or not

I'm working on a plugin that I have to release in parts. The problem is, if there is a menu in the page then add the new plugin to the 2nd or next submenu else add a new menu and then add the plugin ...
Kaushik Kishore's user avatar
12 votes
3 answers
13k views

Remove a menu item in menu

I know this has been asked many times. But from what i got after searching, i could not understand much. I have used wp_update_nav_menu_item to add menu items programatically. But i don't know how to ...
Chetana Kestikar's user avatar
12 votes
1 answer
11k views

Using a menu walker add a custom item at the end of the menu's items

I need to add a search field at the end of a menu in a list item. I've been looking at walkers but finding it really hard to figure out what is the last item (or even get the total). Also where would ...
v3nt's user avatar
  • 1,689
11 votes
4 answers
17k views

wp_get_nav_menu_items() not working with slug

According to the docs, wp_get_nav_menu_items() parameter 1 accepts (string) (Required) Menu name, ID, or slug. Here is how I'm registering my menus register_nav_menus( array( 'primary' =...
somebodysomewhere's user avatar
11 votes
4 answers
11k views

Add a custom walker to a menu created in a widget

I know how to add a Walker to a custom menu created by the theme (menu named primary in this example), but how can I target a menu thats created in a widget with the default wordpress custom menu ...
amy's user avatar
  • 385
11 votes
1 answer
2k views

Add settings to menu items in the Customizer

WordPress 5.4 added the wp_nav_menu_item_custom_fields_customize_template hook to add custom fields to the Nav Menu Item settings in the customizer. I've figured out how to display the additional ...
helgatheviking's user avatar
11 votes
1 answer
29k views

Add custom menu item using wp_nav_menu_items filter

I have added a snippet to add a "Profile" link to my website navigation menu. My code: add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link'); function my_nav_menu_profile_link($menu) { ...
Hafsal's user avatar
  • 113
11 votes
4 answers
21k views

Change the_title() of a page dynamically

I'm developing a plugin that doesn't use a custom post type, but separate database tables. It's a plugin that displays a list of courses with links that lead to the different course detail pages, ...
Gchtr's user avatar
  • 460
11 votes
7 answers
70k views

How can I display a menu on certain pages only?

Instead of using sidebar widgets to tell on what page they should be visible, I like to choose at the menu settings to appear on specific pages. Default Wordpress way: So projects is a page and has ...
user avatar

1
2 3 4 5
65