Change Wordpress menu names in child them - php

My parent theme (html5blank) has 3 menus set up my default in it's functions.php. I want to amend their names in my child theme so they make more sense for my client.
I've tried copying the code into my child theme functions.php and renaming the register_html5_menu function but it won't work as there's no reference to the menus in the templates - presumably because this function is related to the CMS?
Here's the code from the parent theme:
function register_html5_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'header-menu' => __('Header Menu', 'html5blank'), // Main Navigation
'sidebar-menu' => __('Sidebar Menu', 'html5blank'), // Sidebar Navigation
'extra-menu' => __('Extra Menu', 'html5blank') // Extra Navigation if needed (duplicate as many as you need!)
));
}
Can anyone think of away to amend the names/possibly add new menus via the child theme functions.php?
Also, what is the second 'html5blank' name for? "Header Menu" is the only thing that shows up in the CMS and I see these 'second comments' throughout the functions file. Just wondering what they do, if anything?

The register_html5_menu() function needs to be called the snippet you provide only defines the function.
Can you try adding
add_action( 'after_setup_theme', 'register_html5_menu' );
to your functions.php file after the function.
On you question about the second 'html5blank' I think is more a question about the translation text function __()
More info here:
https://developer.wordpress.org/reference/functions/__/

Try this
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'header-menu', __( 'Header Menu' ) );
register_nav_menu( 'sidebar-menu', __( 'Sidebar Menu' ) );
register_nav_menu( 'extra-menu', __( 'Extra Menu' ) );
}

Related

Add Two Way Menu In WordPress For Login And Logout

I am looking to add tow menus in wordpress theme using hooks. One menu should show on when members logged in my system and second menu will show when members are logout from system.
I am using below code but it's showing only for logged out users.
function custom_new_menu() {
register_nav_menus(array('custom-menu' => __( 'Custom Menu' ),'extra-menu' => __( 'Extra Menu')));
}
add_action( 'init', 'custom_new_menu' );
You can utilize the is_user_logged_in() function to check if the current user is logged into Wordpress.
function custom_new_menu() {
if (is_user_logged_in()) {
register_nav_menu(
// Loads the additional nav for logged in users
'extra-menu' => __( 'Extra Menu')
);
} else {
register_nav_menu(
// Loads the default nav for visitors
'custom-menu' => __( 'Custom Menu' ),
);
}
}
add_action( 'init', 'custom_new_menu' );
Note that the code above switched from the register_nav_menus() which registers multiple menus to register_nav_menu() which registers a single menu. The syntax for these is slightly different as we no longer need the inner array.

Function not showing up in child theme WordPress

I was having problems with functions in the Aaron child theme in WordPress. I had part of my problem answered in Overwrite parent functions in child function.php WordPress but I couldn't get the logo to work as a bigger size. I eliminated a lot of code in order to narrow down and find the problem. And what I found is that the function in child theme wasn't showing up in WordPress. This is the function:
/* Site Logo */
function add_site_icon_support() {
$args = array(
'header-text' => array(
'Site Title Here',
'Your site description goes here.',
),
'size' => 'medium',
);
add_theme_support( 'site-logo', $args );
}
add_action( 'after_setup_theme', 'add_site_icon_support' );
I tested it out by adding it to the functions.php in parent theme and it works. Therefore, I was wondering how to make it work in the child theme?
Does it have something to do with this function in parent theme?
function aaron_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on aaron, use a find and replace
* to change 'aaron' to the name of your theme in all the template files
*/
load_theme_textdomain('aaron', get_template_directory() . '/languages');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
add_theme_support('woocommerce');
add_theme_support('jetpack-responsive-videos');
add_editor_style();
add_theme_support('post-thumbnails');
add_image_size('aaron-featured-posts-thumb', 360, 300);
add_theme_support('title-tag');
register_nav_menus(array(
'header' => __('Primary Menu', 'aaron'),
'social' => __('Social Menu', 'aaron'),
));
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
}
endif; // aaron_setup
add_action('after_setup_theme', 'aaron_setup');
Since both have the same hooks.
You need to run your hook later than the parent theme. You need to remember, child theme load first, then parent theme.
To make your function work, you need a lower priority, which is a higher number. You can try
add_action( 'after_setup_theme', 'add_site_icon_support', 11 );

wp_nav_menu only prints menu if I don't include the location (which was registered)

I was able to register a new menu location (it shows in the admin Appearance->Menus section. But when I call wp_nav_menu with that location, it prints nothing. If I set location =>'' then it prints it!
functions.php
//This works
add_action( 'init', 'register_my_menus' );
function register_my_menus()
{
register_nav_menus( array( 'my_special_slug' => __( 'My Menu' )));
}
header.php
wp_nav_menu(
array(
'items_wrap'=> '%3$s',
'walker' => new MyWalker(),
'container'=>false,
'menu_class' => '',
'theme_location'=>'my_special_slug', //This does NOT work
'fallback_cb'=>false
)
);
What am I doing wrong?
register_nav_menu takes a comma separated array.
function register_my_menus()
{
register_nav_menu(array( 'my_special_slug', 'My Menu');
}
It appears (please correct me if this is incorrect) that without the user going into the admin interface and turning the menu on, it cannot be found. They need to go to `Appearance->Menus->Locations" and select the menu to show for that location.
I have been unable to find a programmatic way of doing this.

each plugin i make i have a issue with the add menu and submenu pages

So what i mean by the above is. I've so far made many plugins but i keep getting this issue which i don't know how to describe and that is why i cant search it on google.
What happen is in many plugin a main menu is required and under it several sub-menus that leads to different pages related to the plugin. you can click on the main menu lets say "car" and that will take you to a add car page. and there will also be a sub-menu called add car.
like: posts - when you click on posts for example it takes you to all post, but there is also a sub-menu that is called all post.
What i am having problem with is the main menu is named one thing and when hover it the first sub-menu is also called the same.
My question is:
How can i make it so that either when creating a main menu it will not automatically add a sub menu or if it does. the name will be different then the main menu.
I hope the explanation is clear - i really tried.
Here is how i define my menus:
function my_plugin_menu() {
add_menu_page( 'add_deal', 'Add Deal', 'manage_options', 'add_deal', 'menuload_add_deal', '', '28');
add_submenu_page( 'add_deal', 'deals', 'Deals', 'manage_options', 'deals', 'menuload_deals');
add_submenu_page( 'add_deal', 'orders', 'Order', 'manage_options', 'orders', 'menuload_orders');
add_submenu_page( 'add_deal', 'gc_options', 'Options', 'manage_options', 'gc_options', 'menuload_gc_options');
}
add_action( 'admin_menu', 'my_plugin_menu' );
The above now display for me:
Add Deal - //opens add deal page
Deals
Orders
Options
I would like to change it to:
Shopping Cart - //opens add deal page
add deal - //opens add deal page
deals
orders
options
Ones again i hope that makes sense.. not trying to waste anyone's time but that's why its so hard for me to find info on googble about this issue. (i don't know how to describe the problem well).
I've found a solution incase anyone interested:
function my_plugin_menu() {
add_menu_page( 'add_product', 'Bass Nation', 'manage_options', 'bass-nation-real-shopping-cart', 'menu_load_add_product', '', '28');
add_submenu_page( 'bass-nation-real-shopping-cart', 'add_product', 'Add Product', 'manage_options', 'bass-nation-real-shopping-cart', 'menu_load_add_product');
add_submenu_page( 'bass-nation-real-shopping-cart', 'products', 'Products', 'manage_options', 'products', 'menu_load_products');
add_submenu_page( 'bass-nation-real-shopping-cart', 'orders', 'Orders', 'manage_options', 'orders', 'menu_load_orders');
add_submenu_page( 'bass-nation-real-shopping-cart', 'bnrsc_options', 'Options', 'manage_options', 'bnrsc_options', 'menu_load_options');
}
add_action( 'admin_menu', 'my_plugin_menu' );
You just name the first sub menu's slugen same as the main menu.
Hope this helps someone out there.

Wordpress Navigation Help

I am working on a site that calls the categories of a wordpress page and displays them in the right-side navigation using a php call. I am new to php and web programming in general. Is there a way I could split the categories into two sections using a particular php call or perhaps an if-loop.
Essentially, I want to display particular categories under custom sub-headings to better organize the site. Any help, I'm currently using the following script to display my categories:
<ul><?php wp_list_categories('show_count=1&title_li='); ?></ul>
Here is my site for reference: http://www.merrimentdesign.com
Try using your code above twice. Each time, you can use the other function arguments to limit the output to certain categories. See http://codex.wordpress.org/Template_Tags/wp_list_categories for the various ways to customize the output of the function.
For example you could use:
<ul><?php wp_list_categories('show_count=1&title_li=&child_of=100'); ?></ul>
// where 100 is the parent id of all of the categories you want to print.
<ul><?php wp_list_categories('show_count=1&title_li=&exclude_tree=100'); ?></ul>
// and then show everything, but children of 100
Or simply use the first string multiple times specifying different parent ids each time.
By far and away your best option is to use the new menu functionality within WordPress. It's dead straight forward to set up in your theme:
add_theme_support( 'menus' );
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'public-menu' => __( 'Public Menu' ),
'sidebar-public-menu' => __( 'Sidebar Public Menu' ),
'sidebar-members-menu' => __( 'Sidebar Members Menu' ),
'sidebar-staff-menu' => __( 'Sidebar Staff Menu' ),
'footer-menu' => __( 'Footer Menu' )
)
);
}
place that in your functions.php file (and obviously change it for your requirements).
Then in your template file - probably sidebar.php you'll want something like:
<?php wp_nav_menu( array( 'theme_location' => 'sidebar-staff-menu', 'container' => false ) ); ?>
And then go to the back end of WordPress (your wp-admin) and then go to Appearance > Menus and voila you're able to drag and drop your categories to your heart's content!
Helpful link: http://justintadlock.com/archives/2010/06/01/goodbye-headaches-hello-menus
Read that, Justin Tadlock is awesome.
Good luck.

Categories