How to add a new header menu in wordpress? - php

How to add a new header menu in wordpress?

You may add a function to wordpress (well anywhere in your theme) using the wp_nav_menu(). This requires that you add the code below to your functions.php file (if you do not have one in your theme directory then create one):
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'menu-1' => __( 'Top menu' ),
'menu-2' => __( 'Bottom menu' )
)
);
}
Change the "Top menu" and "Bottom menu" to what ever you want the names to be. Basically you are just telling wordpress (wp 3.+) to make reservations for these menu in your theme. If you want more you just need to define the names in a new line. Save that.
That done you will need to add the menu in your site template. Usually I define the arguments first before I call the wp_nav_menu() function. Read up on the arguments here http://codex.wordpress.org/Function_Reference/wp_nav_menu
Hope that helps.

You can manage the menus in your WordPress dashboard under "Appearance => Menus". Here is a tutorial: http://en.support.wordpress.com/menus/

Related

How to create and customize a menu in word press 5.8 by coding

I'm new to word press. For creating a new menu, I'm using register_nav_menus()
function inside functions.php to register a menu. But I still need word press admin panel to add items in a menu e.g contact, about us pages. How can I add these options by coding instead of using admin panel of word-press.
function register_menu(){
register_nav_menus(
array(
'primary-menu' => 'Primary Main Menu',
'footer-menu' => 'Footer Menu'
)
);
}
add_action('init', 'register_menu');

Menu is not showing in admin panel

I try to make my own theme in wordpress. Stucked a problem: i can't see menu button in admin panel. I've registered menu in functions.php of my theme
<?php
register_nav_menu( 'menu', 'Menu on the main page' );
?>
But there is no menu button appear in admin panel - appereance. I did all that was recommended on youtube video (https://youtu.be/I0zu6Dc3JDI?t=95). Nothing. Please help =) I have last version of Wordpress.
You was half way there, you had the right idea for registering the menu however you missed out telling WordPress to run your register menu command.
What you need to do is wrap it in a function and call the function on 'init' which is the initialisation of the admin area (one of many WordPress hooks), see below:
function register_child_menus() {
register_nav_menus(
array(
'my-menu' => __( 'My Menu' )
)
);
} add_action( 'init', 'register_child_menus' );

Overwrite $wp_customize from wordpress plugin

I am using a simple theme in WordPress, that pulls it's customizers sections from the plugin ThemeHunk Customizer.
I want to hide certain sections in the customizer section, but when using $wp_customize, it isn't working.
This is what I am trying to hide:
$wp_customize->add_section('section_home_ordering', array(
'title' => __('Section Ordering', 'featuredlite'),
'priority' => 3,
));
This is located in the /wp-content/plugins/themehunk-customizer/featuredlite/customizer/customizer.php file.
I have added this to my functions.php file in my child theme directory:
function customize_register_init( $wp_customize ){
$wp_customize->remove_section('section_default_home');
$wp_customize->remove_section('pro_button');
$wp_customize->remove_section('Docs_button');
$wp_customize->remove_section('section_home_ordering'); - THIS IS THE SECTION I would like removed from the /plugin/ file
}
add_action( 'customize_register', 'customize_register_init', 99 );
It doesn't seem to remove though, like it would if you were removing a section from a parent theme.
Is there another method to do this, or is this not possible to remove from a plugin rather than a parent theme?
Thank you in advance.
SOLVED I use the customize_controls_enqueue_scripts hook to input custom CSS within the wordpress customizer, so I can display certain elements as hidden!
In theme your code works fine. Maybe it depends on action hooks order.
Have you tried?
add_action( 'plugins_loaded', 'customize_register_init', 99 );
You can simply go with these documentation as it shows you can disable particular section of Home Page (FrontPage). You can change order of appearance also from the Appearance > Frontpage Section > Section Ordering.
Reference Link: https://themehunk.com/docs/shopline-theme/#frontpage-section
https://themehunk.com/product/shopline-free-shopping-theme/

Wordpress Administration menu pointed to the theme file

I want to add custom menu and sub-menu to Wordpress admin area. I read some info about it in Codex and I added menus using the function below, which I placed in my theme's functions.php
add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', get_template_directory() . '/inc/restaurants.php', 'restaurants_admin_page', 'dashicons-format-aside', 6 );
The menu is added to the Wordpress admin sidebar, but I when I'm going that page it goes to the next link:
http://site.ge/wp-admin/admin.php?page=home%2Fbmtbow%2Fpublic_html%2Ftesting%2Fwp-content%2Fthemes%2Fmytheme%2Finc%2Frestaurants.php
but there is no any content, like it is not pointed to the right PHP file.
Am I doing something wrong? and could you help me to solve this problem?
The add_menu_page function doesn't seem to accept a php file as an argument for content. But it does take a function name. You can call your php file with the content in a function, then pass that function as an argument to add_menu_page. (As a side point, you might have the order of your arguments mixed up. The slug is supposed to be 4th, not 5th.) More information about add_menu_page() and it's arguments can be found here.
Try this:
add_action( 'admin_menu', 'restaurant_menu' );
function restaurant_menu() {
add_menu_page( 'Restaurants Admin Page', 'Restaurants', 'manage_options', 'restaurants_admin_page', 'restaurant_admin_page_contents', 'dashicons-format-aside', 6 );
}
function restaurant_admin_page_contents(){
include get_template_directory() . '/inc/restaurants.php';
}

Wordpress Custom Navigation on Secondary Theme

I've followed the codex; http://codex.wordpress.org/Navigation_Menus
However I believe that because we are trying to do the edits on page that isn't using the main sites theme, it's falling apart.
Our standard theme is Grand College, the theme however we are trying to edit is a BlankSlate theme.
I've made the edits in the BlankSlate functions file and inserted:
function register_my_menu() {
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));
}
add_action( 'init', 'register_my_menu' );
In the header file I've inserted;
<?php wp_nav_menu( array( 'theme_location' => 'example-menu' ) ); ?>
And in the WP-admin dashboard I've built a menu for 'example': I've added Home and Contact to it. However in the 'Manage Location' section I've only got 2 menu options which is what Grand College gives you by default
However when I view the site, I get the 'main' navigation showing rather than just the example menu.
Do my edits to put a new custom menu in, have to be done on the Grand College theme (The sites standard theme, or am I right to be trying to edit the pages theme?
Any help would be great appreciated.
To register a navigation menu i simply used the following code-
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));

Categories