Difference of menu and theme_location - wordpress

I'm trying to create a menu by wp_nav_menu(), there are two argument seems the same although the name are different: menu and theme_location. Assume I already register a menu and the name/id is nice, now I want to display the menu on a page by wp_nav_menu(), this is what I do:
wp_nav_menu( array(
'menu' => 'nice',
'theme_location' => 'nice'
) );
If I don't specify the theme_location, it will still work? Because I already tell wordpress the menu I wanna display, and vice versa, if I specify the theme location, why do I still need to specify menu which I wanna use?

menu and theme_location has some explanations, menu is for specific menu id, slug, name or object where you will show that specific menu by the menu id, slug, name or object, on the other hand theme_location is where you want to show your menu. It is not necessary to set the menu and theme_location at a time, but if you set two options at a time it will priority the menu first then theme_location, in case you have no menu with that name/slug then it will check the theme_location, in case you set a wrong theme_location which is actually not registered then it will call the fallback_cb. Note that menu name comes from the admin panel https://prnt.sc/j-m6B-jY252k where theme_location comes from the functions.php file where you registered the menu https://prnt.sc/BglTqU_xows2 . This theme_location will show in the menu area in the admin panel https://prnt.sc/KY7cYottkJWe . So, in conclusion, you can use any one of it for showing the menu but it is totally up to you which way you will choose, but for developers it is wise to set theme_location instead of menu.
I have tried to explain everything from my end but if you have more questions you can read the official details of menu here

Related

How can I move admin menu top-level items to submenu

I'm using the code at https://markwilkinson.me/2014/11/altering-wordpress-admin-menus/ to change plugin-created top-level admin-menu items to submenu items of a 'misc' top-level item.
It works fine on those items which don't have their own submenu, but on items which have their own submenu the submenu disappears.
I don't know if the code can be appropriately modified, or if it can how to do it.
Wordpress does not allow you to add a 3rd level of menus in WP admin.
See the answer to How to Add a Third Level Sub Menu to the Wordpress Admin Menu from wordpress.stackexchange.com
The answer from Karthikeyani explains why it currently isn't possible:
The definition of add_submenu_page requires the parent slug name. For example:
add_menu_page ( 'Test Menu', 'Test Menu', 'read', 'testmainmenu', '', '' );
add_submenu_page ( 'testmainmenu', 'Test Menu', 'Child1', 'read', 'child1', '');
The first parameter of the add_submenu_page is parent slug name $parent_slug. You may think you could use child1 ($menu_slug) as parent slug name to create the third level, but this does not work.
The parameters definition and source section in the Wordpress developer documentation for add_submenu_page clearly states that you can only use the name of the main menu of the plugin or the file name of the WordPress plugin in parent slug name.
add_submenu_page Ref: https://developer.wordpress.org/reference/functions/add_submenu_page/

Drupal custom theme visibility to all users

I'm creating a custom drupal 7 theme
<?php print theme('links', array('links' => menu_navigation_links('menu-headermenu'), 'attributes' => array('class'=> array('links', 'headermenu')) )); ?>
Above is the code I'm using in my theme to show a menu I created using the Admin section.
My problem is the menu is getting displayed only for the Admin.
I want it to be shown to anonymous as well as registered users.
Also, I've tried changing the role permission by ticking 'Administer Block' and 'Administer menus and menu items' to all the three kind of users. Nothing helps.
Please help me..
I'm not 100% sure this will answer your question, because it side steps the code above - but, you could try enabling the Menu Block module, then using it to create a block based on your desired menu. Then you can place it any block region, and control it via the normal block controls.
The only trick of it is you might need to add a region to your template if it doesn't exist in the place that you want, but that's easy.

main menu on wordpress theme is not carried over to new copy-pasted theme

Sorry, new to Wordpress here.
I copy-pasted an existing theme. Most of it looks fine. However, it seems the main menu style and menu items were not carried over to the new theme. The new theme is unstyled because it has no id menu-top, which the original one has. Also, the new theme has way too many menu items, while the original one only has 4.
What do I change so that my new theme's main menu gets that id, and will contain the same menu items?
I've check the Admin > Appearance > Menu and it correctly has 4 items, but it's not reflected in my new theme.
Also, in header.php, I tried adding 'menu_id' => 'menu-top' to:
wp_nav_menu( array( 'container'=>'none', 'theme_location' => 'primary' ) );
but that didn't change anything.
Help please?
I'm 99% sure, that the problem is that you don't have a menu selected in the "primary" theme location, so WordPress displays all of your pages.
To fix this, go to Appearance > Menus and see if you still have your old menu. If you do, just select this menu in the "Primary" drop-down on the left and click Save.
If you don't have the menu anymore, rebuild the menu and select it for the theme location. After that things should be fine.

Need help with Wordpress menu and redirecting pages

I have a template with 2 menus, a top primary menu and a secondary menu.
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
and these menu options :
Home
Projects
Contact
Now I have a secondary menu that is visible when someone accesses "Projects". and the follwing menu options :
Overview
Project A
Project B
Now in this scenario I have 6 pages, one for every menu option. But I do not want to use the "Project" page. If someone clicks "Porjects" on the primary menu, I want that the "Overview" page is actually loaded.
The second problem is with the style. When I have "Overview" activated I also want to have the secondary menu option "Overview" highlighted, which works, but also the menu option on the primary menu "Projects".
Any idea ?
At least for your first question, using the custom menu, you should be able to add the Overview page in place of Projects, and rename it Projects. That also may fix your second question as well.

create own wordpress theme (tewnty ten as base)

i have to create a customized wordpress theme.
i still don't how it should look like, so viewed the twenty ten theme files to figured out what i could customize.
so i searched for the menu build function in the header.php file and found this
<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?>
<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>
but i cant figure out what this function does...where is written how the menu is created with html tags like <ul>, <li> and so on...
i wan't to edit the html code!
regards,
peter
Check out the documentation for wp_nav_menu in the codex. It's a menu system added to WordPress back at version 2.9 (I believe). If you navigate in your dashboard to Appearance -> Menus, you can customize it through an interface. In Twenty Ten, the fallback is wp_page_menu, which displays a list of your pages. Should you prefer to build yours by hand and hard code it into the theme (not advisable, but possible) just delete the relevant code and replace it with your own HTML.
My adviice is to look into the Menu interface, create a menu, assign it to the theme position 'primary', and go from there with a properly configurable and WP-driven menu.

Resources