Creating a second header navigation menu in Wordpress - php

I would like to create a second navigation menu that goes below the main one (The one that contains the "About" and "Contact" etc. categories). This one would have images that have links and also which show text under them when hovered on. I have already created the necessary HTML and CSS for it, I just don't know how I would implement that into my site. The images and links are in a table, but the Wordpress navigation menu is a list, so I'm kind of stuck on what to do.

Are you using a default/premium/free theme, or did you create one by yourself?
I assume the first, so here are a few things you need to know.
Wordpress uses hooks, so you can "link" your code at a certain point of their code, when a website is called. In its codex, you can learn more about how navigation menus are registered and called later on.
A theme is something like a base, when you create your own website. You can create child themes and implement every further functionality and design changes
right there.
In short: implement your menu, put it in your child theme and use the hooks to get it where you need.

Standard way of adding a secondary menu to a theme is as follows.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'yourtheme'),
'secondary' => __( 'Secondary Menu', 'yourtheme' ),
) );

Nevermind, the question I was trying to ask is where do I put my HTML code of the table so that it shows up on the header, but I found the solution through sheer luck. I put the HTML into the header.php of my child theme and linked the CSS classes to those that I pasted into the style.css . Still, thanks to those who tried to answer!

Related

Left Sidebar on Wordpress won't create menu

I tried googling this, but not having much luck...
I have been able to create a menu using wordpress and entering this code in my header:
<?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
And this in my scripts part:
function register_custom_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_custom_menu' );
But it seems that when trying to sort it, using the left side bar in the customize theme mode, it will not sort the menu nor will it remove any part of the menu that I add or remove using it.
From what I can tell it's just pulling my pages that I created within wordpress.
Keep in mind, this is a new theme I'm creating - my first theme. I have no PHP experience. Trying to learn as I go.
Picture of issue
I removed some of the names of the links for public view. I need to figure out how to also style this properly, but I've seen some other posts about it, so I'll review those later.
If someone can help me get this side menu to work with my current menu that would be great!
If you try altering your wp_nav_menu call to the following (no parameters):
<?php wp_nav_menu(); ?>
It should fall back on the first non-empty menu. While you may want additional menus later/will likely want to customize your menu(s) more, this should help with troubleshooting as whatever initial menu you have created (is non-empty) is the menu being edited by the customize page.
From what I can tell it's just pulling my pages that I created within
wordpress.
This likely relates to the setting "Automatically add new top-level pages to this menu" in the menu settings tab. This may be found under Appearance >> Menus, or under Customize >> Menus >> Clicking on the arrow to the right of your primary menu >> menu options (at the bottom of the resulting tab on the left).
Have you tried building the menu through Appearance-->Menu?
In the Wordpress backend, go to "Design > Menus", create a new menu there, add all entries you want to have, give it a name and in the "positions" tab on that page, assign it to the defined position in your theme (header-menu in your case). And disable the option to add all new pages/posts automatically.

Is it possible to hook a text box into a WordPress theme, via the functions.php file?

I am currently using a WordPress theme to create an ecommerce website. I am looking to create a horizontal text box, with 3 columns, to appear directly beneath the Main Menu navigation. Rather than edit the header.php file, and risk breaking the theme, is it possible to achieve this by hooking into the theme, via a functions.php file in the child theme or would thus be bad practice?
So adding "right after the main menu" is not something WordPress will be able to give you directly, no. Because, by definition, the structure of a page is a theme's responsibility.
That would be a perfect case for a child theme, and it would be my first choice. There you can safely override the index file (or header file, depending on how the theme is built) and add your html to it.
Another option a child theme might give you, is adding html through the theme's own filters and actions - but that will totally depend on your theme giving you such hooks.
Finally, if truly you want to add right after the main navigation, you might look at the wp_nav_menu filter: using that, it should be possible to first detect if you are looking at the main navigation or not, and if you are, append your own html. But frankly, I think the risk of breaking your layout is greater with that method.
Hope this helps!

Order Pages in Wordpress

I am new to CMS development, I prefer the MVC concept for every job. But just know the client requested to develop a website built in WordPress. Everything is OK but I can't find to order pages in WordPress.
The case is: first I create a home page and then I create other pages, but the problem is every time I add new pages, it will be placed in my first menu.
So I want to move the home pages in first menu.
Please help, thanks.
You can create a custom menu (with the pages/links you want, and the order you want !). Then you can add that menu to be the new navigation menu (both header, and footer if you want)
References:
WordPress Menu (here you can find the step by step 'guide')
Just go to Appearance --> Menus and then you'll be able to create menus and edit at will. And if you need to create specific menus, see WP nav menu page. There you'll see several code samples, but you'll need something as simple as
<?php wp_nav_menu( array('menu' => 'Main Nav' )); ?>

How to insert secondary menu on TwentyThirteen theme in WordPress?

I am currently using Twenty Thirteen theme and I want to create a secondary menus. I am not entirely familiar with the PHP codes. I was wondering if you know how to insert the proper code in function.php? Also, do you know the code to insert in header.php page?
Here is the example of codes from Twenty Eleven theme:
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'yourtheme'),
'secondary' => __( 'Secondary Menu', 'yourtheme' ),
) );
<nav>
<?php
wp_nav_menu( array('container_class' => 'menu-footer',
'theme_location' => 'secondary') ); ?>
</nav>
Thanks!
by secondary menu, i assume you mean a sub menu? this is done in the wordpress cms. first create the pages, then go to the menu module and add them to the primary menu you have already set up. then they will appear with when you call the menu. you will have to stylize them in css to get them to be a nav bar and there are tons of tutorials and already answered questions on that.
if you are creating a second separate menu, then you are on exactly the right track with registering the menus. but then you want to call them with the wp_nav_menu() in different places, unless you want to join the menus, which you can do by placing <ul></ul>around the php code.
always actually create the pages and menu wordpress and once you register it, be sure to go back in to the menu and link the menu to the location under the manage location tab. check codex if you don't know what i mean. you may have forgotten that step. good luck!

Programming custom PHP with Wordpress

I have a question regarding PHP and Wordpress.
I recently started using Wordpress for a simple website but there is still one thing that I just don't understand. Lets say I made a cool website in php that also cointains my header, my footer and my menu. How do I implement the Wordpress CMS so that someone else can add an item in the menubar that I made, instead of adding an item in a theme made by someone else? I have a hard time finding such tutorials because most of them are for people with no programming interests and because of that they don't explain such things.
If your only concern is how to connect your menu to the wordpress admin, you can check this link: wp_nav_menu()
that wordpress function will then generate a list of the menu items you add on the admin.
For example use this on your theme to display a menu from the admin with the name "Main Menu":
<div class="my-menu">
<?php wp_nav_menu(array('menu' => 'Main Menu' )); ?>
</div>

Categories