New answers tagged

1

The docs for register_nav_menu show an example using the after_setup_theme hook so I would use that. after_setup_theme This hook is called during each page load, after the theme is initialized. It is generally used to perform basic setup, registration, and init actions for a theme. ...the after_setup_theme hook, which runs before the init hook. The ...


2

First off, you should not register functions loose in functions.php because you cannot remove them (using remove_action). It can also cause debug errors since WP may not yet be stable. By using a hook you are making sure WP is stable enough to run your code, and what you need to use has been loaded. Check out the answer on the Wordpress Forums for more info ...


1

You can use them the moment they are available i.e. as soon as functions.php is loaded, hence why you've seen so many different options. I would recommend sticking with the "defacto" way - using the hook after_setup_theme


1

There are a few ways to do this and they mostly revolve around the walker_nav_menu_start_el filter. I'd be inclined to add custom fields to the nav menu items: one for the image and one for the image's alternate text. That way, users can update the images and developers aren't required to keep a hash of all menu items and related image URLs/alt text in code ...


0

Use the checked function. https://codex.wordpress.org/Function_Reference/checked The HTML you want to render should look like this: <input ... value="hide" checked="checked" />Hide from these locations.</br> <input ... value="show" />Only show to these locations.</br> What you're getting instead is probably somthing like this: ...


0

After a bit of debugging, I was able to narrow this down to the following: The menu that I had created to display across each site in the network was comprised of Custom post types that were not registered on any other subsite, only the main site (1). For whatever reason the custom post type must be registered on each site in the network where you will ...


0

That is perfectly fine behaviour of WordPress. You can´t just paste markup in the href field, the input gets sanitized. Use the built-in functionality to provide special links with classes if you want a different styling. See the attached image for those fields. You will have to activate those options through the options tab at the top of the page, though. ...


1

Well, you wouldn't need a walker for that, if it's simply adding a data attribute or something like that you could just use the items_wrap parameter. View wp_nav_menu() in Resources: $items_wrap = '<div class="top-nav" mine="something">'; $items_wrap .= '<ul id="%1$s" mine="something2" class="nav %2$s">%3$s</ul>'; $items_wrap .= ...


0

There are 4 arguments that might help you with wp_nav_menu(): before – "(string) Text before the link text." after – "(string) Text after the link text." link_before – "(string) Text before the link." link_after – "(string) Text after the link."


2

Please Try with bellow : wp_nav_menu( array( 'theme_location' => 'header_menu', 'container_id' => 'menu', 'walker' => new description_walker() ) ); And Add functions.php class description_walker extends Walker_Nav_Menu{ function start_el(&$output, $item, $depth, $args){ global $wp_query; $indent = ( $depth ) ? ...


2

Solution 1: Using customize walker I got some idea from add span class inside wp_nav_menu link anchor tag and make some change as your requirement. 1. Add this code below to your functions.php first. class Nav_Walker_Nav_Menu extends Walker_Nav_Menu{ function start_el(&$output, $item, $depth, $args){ global $wp_query; $indent = ( ...


0

You added the menu only for the destop view. For mobile menu goto dashboard->Appearence->menu->Menusetting-> select theme location for mobile


0

The mobile nav menu in your theme appears to be injected via JavaScript. On pages other than the home page the mobile nav does appear. It looks like the home page is the only page throwing JS errors; they appear to be associated with Mailchimp and/or Contact form 7 . Try disabling plugins for both Mailchimp and CF7.


1

As far as I am aware, there is no native way undo menu changes. However I did find this plugin Menus History, however I haven't tested it and it will only save changes in the future


0

Now it works. Im very grateful to jgraup! All that I needed to change is to add $icon = $GLOBALS[$icon_var]; and change the $menu_list structure as jgraup recommended. Even there is no need for third-party changes. The final code: function sidebar_menu() { $menu_name = 'sidebar_pages'; if (($locations = get_nav_menu_locations()) && ...


0

You need to call global $variable; before you can use the variable. Try the code below instead for that line. // setup your global scope here global $icon_var; // set the new value in global scope $icon_var = get_post_meta($menu_item->ID, '_menu_item_custom', true); // then use the variable $menu_list .= "\t\t\t\t\t<li><a ...


2

Not sure, but maybe something like this will work? Add to the functions.php. See explanation here. //This function is responsible for adding "my-parent-item" class to parent menu item's function add_menu_parent_class( $items ) { $parents = array(); foreach ( $items as $item ) { //Check if the item is a parent item if ( $item->menu_item_parent ...


1

There is a navigation menu plugin extension for the REST API v2: https://wordpress.org/plugins/wp-api-menus/


0

Ok, so I managed to sort this out in the end by renaming the front-page.php file so that it's not picked up. If I have missed anything or anyone can suggest something I should have done, please let me know.


0

You need to add 'show_in_rest' => true, while registering post type. See details here http://v2.wp-api.org/extending/custom-content-types/


0

You can use the wp_nav_menu() arguments like so: wp_nav_menu( array( 'menu' => 'Whatever Your Menu Name Is', 'link_before' => '<span class="main-nav__item-icon-wrapper"><i class="main-nav__item-icon icon-home"></i></span><span class="main-nav__item-content">', 'link_after' => '</span>' ) ...


3

This is most likely a result of different Screen Options selected between each site. While on the menu editor, look in the top right corner for the Screen Options pull down. On that panel, you should have the option to hide or show (via checkbox) details such as the title attribute, link target, CSS classes, etc.


2

If you are trying to get the post type for the current 'post', I think you could go with get_post_type(). Like this: $post_type = get_post_type(); Try it out.


0

To add a new attribute to your anchor link for the nav items concatenate $attribute variable with your required attribute. You have commended code just uncomment the code and use those $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_atta( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' ...


1

Try using the following code. .current-menu-ancestor > ul { display:block; } The class current-menu-ancestor appears if the current item is a parent of a current page item.


-1

The change to be done is to change: $item_output .= '<a'. $attributes .'>'; to $item_output .= '<a itemprop=url'. $attributes .'>';


0

You need to modify the rewrite argument when you register your post type: $args = array( // [...] 'rewrite' => array( 'slug' => "Tours" ), ); register_post_type( mc_tours, $args );


0

I just wrote this : https://gist.github.com/vwasteels/874f7d08726076bdc580 It will fetch recursively and generate an array with children embedded in each item. This will work with menu of any depth.


-2

I know you had this issue long time ago but since this site popped up with the first few, I thought to share my solution in case someone needs it.


1

You should call wp_nav_menu() in your footer.php template. It's used as following : <?php wp_nav_menu( array('theme_location'=>'footer') ); ?> The theme_location parameters refers to the checkboxes below the menu editor (Theme location). If your theme doesn't have enough theme_location, you can add some by adding function ...



Top 50 recent answers are included