Tag Info

New answers tagged

0

Figured this out. Bootstrap's dropdown doesn't go to the third level. You have to add another plugin or custom code to make it work.


1

My solution to this problem when extending the Walker_Nav_Menu was to skip check if current_page_parent when C.P.T. I identified C.P.Ts following this stackexchange post. This does not entirely solve the problem as I am using current_page_item for C.P.T parent menu items, but it does achieve the desired outcome. Here is my class. class My_Menu extends ...


0

Given the amount of customization you're looking to make, your best bet may be to integrate a custom Walker function. From the Codex: For deeper conditional classes, you'll need to use a custom walker function (created in the 'walker' => new Your_Walker_Function argument). The easiest way to build a new walker function is to copy the default ...


2

I've asked this question a bit to early, but to help others in the feature here's the solution. For the menu editor to appear, you need to register a menu first: add_action( 'init', 'register_header_menu' ); function register_header_menu() { register_nav_menu('header-menu',__( 'Header Menu' )); } Or as pointed out by Howdy_McGee: add_theme_support( ...


0

Menus are included in native WordPress export. It's not too convenient that natively you can't only export menus though. From quick look up there is WordPress Menu Exporter plugin available in official repository for that. Export/import aside there are more options to automate it, such as set up scripts with WP CLI or simply using PHP code to detect empty ...


0

There are a few code edits you might have to do.. So lets go step by step.. Change in the places you use, <?php echo esc_url( home_url( '/' ) ); ?> to get the home page url, you can replace it with <?php get_site_url(); ?> which will get you your site URL. Next you are using the code of Site Title, <h1 class="site-title"><a ...


1

I've made a free plugin which solves this problem! https://wordpress.org/plugins/wp-nav-menu-extended/ This plugin extends the native wp_nav_menu function and adds additional options: level : (integer) (required for this plugin to work) The level of the navigation menu to show. If no child_of parameter is passed, it shows all the items of this level ...


0

Thanks for your help Did you try with location slug? Take a look at where your menu location is defined (functions.php) Yes, I was use this function to convert menu name to slug but same results... function wp_menu_id_by_name( $name ) { $menus = get_terms( 'nav_menu' ); foreach ( $menus as $menu ) { if( $name === $menu->name ) { ...


1

Since WordPress 3.0, you don't need a custom walker anymore! There is the walker_nav_menu_start_el filter, see https://developer.wordpress.org/reference/hooks/walker_nav_menu_start_el/ Example: function add_description_to_menu($item_output, $item, $depth, $args) { if (strlen($item->description) > 0 ) { // append description after link ...


0

I tried with the name and the slug and different menus but I always find that error. Did you try with location slug? Take a look at where your menu location is defined (functions.php), for example: register_nav_menus( array( 'primary' => __( 'Primary Menu', 'mytheme' ), ) ); On Appearance->Menus assign your menu to that location. And then ...


0

You can modify the arguments that the search query uses so it will return empty terms. This is a quick hack job, perhaps someone can improve this. I put it together by looking at the browser console when performing a search. There you can see the parameters it's sending to admin-ajax.php to perform the search. In the case of searching for a term in the ...


0

In WordPress 4.1.1 at least, In the Menu editor, Categories > View All Tab shows empty categories.


0

I know this is a long time after the question, but I had the same issue as mentioned in the question. I found no suitable solution in tutorials or on any stackexchange and in the end gave up and wrote my own code for it. I've since published it as a plugin: Bop Search Box Item Type For Nav Menus Crucially, this adds the search box as a menu item option ...


0

Check user capabilities or roles when registering the navigation menu. The data will remain accessible via wp_nav_menu, but users without the capabilities won't see the location in Appearance -> Menu -> Manage locations. Note this will only prevent assigning menus to these locations. Any menu assigned to the location already will be manageable (if the user ...


0

Ended up doing this, which seems much more simple: if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category->cat_ID) != "") { // This is the Template for Category level 1 include(TEMPLATEPATH.'/location.php'); } else{ // This is the Template for Category level 2 ...


0

While it is a guess, rather than certainty, the issues with menus typically boil down to following — working with them involves submitting large and complicated POST requests to server. And what on server has issue with large and complicated POST requests? Security software! The first item to check in such case is usually going to hosting support and ...


1

You could use the template_redirect hook to check and see if your post is a category and then whether it is a sub-category ... and if so, force a different template. For example (assuming you are using wordpress categories) function my_maybe_override_category_template( $template ) { # Make sure you are about to show a category term if ( ...


0

As an alternative to @janw's answer, you can insert the following code in the theme’s footer.php file right before the closing body tag . <!-- Highlight parent page link when on child page --> <?php if (is_page()) { // displaying a child page ?> <script type="text/javascript"> ...


2

This is the code I'm using, it's a custom nav walker for BootStrap but you could easily adapt it to your own. By the way, you could copy & paste my nav walker and be sure to change this line: $class_names .= ' dropdown'; to $class_names .= ' sub-menu'; Hope this helps. /** * Custom Bootstrap Nav Walker */ class macho_bootstrap_walker extends ...


0

I think i have a function that will do it for you. The usual WP way to highlight the menu item is to add the class "current-menu-item" to the item, then you can style highlighted links with CSS. In this case you want to highlight a taxonomy menu link if we're in a post for that taxonomy, is that right? For example if we're in a post in "CategoryX" we want ...


1

I'm new to WordPress myself, but I think answering questions is a good way to learn. There may be a way to use hooks, but I couldn't figure that out, so went ahead with directly editing header.php. I tried the following: From Appearance, Menus, I added a new menu and named it Vert_Menu_test I chose to add the menu to the top left corner of my test site: ...


0

The reason your PRODUCTS menu is appearing first is because you're echoing it out to the page as part of the filter function. The expectation with filters is that your function receives an argument, $items in this case, modifies it and then returns it to be used by the core code. In order to avoid having to rewrite the code that generates your PRODUCTS ...


0

Hard code the container instead, remove it like this: $args = array( 'theme_location' => 'XXX', 'container' => false ) and hard code it around the wp_nav_menu, remembering to add your static section in wherever you need it: echo '<ul>'; echo '<li><a href="http://...">Static Link</a></li>'; wp_nav_menu($args); ...


0

To specifically target a page and show its children/siblings you can use wp_list_pages(); eg. wp_list_pages(array( 'child_of' => "page parent ID", 'depth' => 2 ));


0

Is this what you are after? <?php if($post->post_parent) { // if $post has parent than it is "Second level" and show its children. $children = wp_list_pages("child_of=".$post->post_parent."&echo=0"); } else { // else it's a "Top level" so display children & grand children? $children = ...


1

OK got it. For anyone who needs to do this , it is best you extend Walker_Nav_Menu class if you just need to add things to existing wp menu structure. Otherwise if you are extending Walker class you kinda have to rebuild the menu completely. Include this class class Walker_Extend_Menu extends Walker_Nav_Menu { // Tell Walker where to inherit it's ...


1

I believe what you are looking for is a custom nav walker to control your HTML structure. The WP Codex article lists a good example for controlling the HTML structure of a menu http://codex.wordpress.org/Class_Reference/Walker#General_Menu_Example // Tell Walker where to inherit it's parent and id values var $db_fields = array( 'parent' => ...


0

Add this after your function; do_action('my_custom_fields'); This will force wp to complete all registered callbacks assigned to said action.


0

As I originally suspected, menu-item-parent-id takes the id of the menu item and not the id of the parent page. So I referenced the menu item ID and passed it into the recursive function : function buildMenu( $array, $menu_id, $parent_id = false ) { foreach ($array as $menu) { $menuItemId = wp_update_nav_menu_item( $menu_id, ...


1

You are checking against just one parent item. Instead, you might check against all of the parents <?php //in functions.php add_filter('nav_menu_css_class', 'highlight_portfolio', 12, 2); function highlight_portfolio($classes, $item) { $parents = get_post_ancestors(); if ( 0 < count($parents) ) { if ( in_array( $item->object_id, ...


1

If you want to get the corresponding post ID's from a given menu id, try: $menu_id = 'mymenu'; $items = wp_get_nav_menu_items( $menu_id ); $ids = ( $items ) ? wp_list_pluck( $items , 'object_id' ) : array(); where you have to modify the $menu_id to your needs.


0

Soooo, I have tried the solution with javascript. It works without problems. For debug test: <script> $(function() { alert($('.menu-item').attr('id')); }); </script> It gives me the id from every element in the nav out as alert. I extract now the number at the end and have then the menu-item-id. thanks for all answers, ...


0

html mark up for navigation will look like this <ul id="menu-res" class="main-menu"><li id="menu-item-72" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-72"><a href="#home">Home</a></li> <li id="menu-item-238" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-238"><a ...


0

Based on your comment that the mashable.com menu is what you are going for, I'll be assuming that you want to structure your HTML similar to that (which is to say ul.menu > li > a + ul.submenu + ul.featured-content). That said, that's really implementation details which you can refine for your use case. Before I get into the code, I should note that ...


0

Add this code function.php function replace_last_nav_item($items, $args) { return substr_replace($items, '', strrpos($items, $args->after), strlen($args->after)); } add_filter('wp_nav_menu','replace_last_nav_item',100,2); Add this code menu <?php $defaults = array( 'menu' => 'footer-menu', 'container' => 'ul', ...


0

Congrats on figuring it out. Perhaps this would also work: function change_menu($items){ foreach($items as $item){ if ($item-> post_name == 'the-slug')/*replace "the-slug" with menu item post_name */ $item->url = bp_loggedin_user_domain() . '/events/my-events/?action=edit'; } return $items; } add_filter('wp_nav_menu_objects', ...


0

As I am using the roots theme framework, this line removes the container argument: function roots_nav_menu_args($args = '') { $roots_nav_menu_args = array(); $roots_nav_menu_args['container'] = false; if (!$args['items_wrap']) { $roots_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>'; } if (!$args['depth']) { ...


0

I figured it out with a filter function. This finds the nav menu obj matching the given slug and then modifies it's URL. I left the Menu item with visibility control in my dashboard menu. The URL is initially blank. Added to functions.php: function getUN() { global $current_user; get_currentuserinfo(); return $current_user->user_login; ...


0

If i understand your question correctly, the first thing you would need to do is, go to your menus /wp-admin/nav-menus.php (screen options) and checkbox (tick) on the description. and this is how your walker class should look like class Menu_With_Description extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { ...


0

Much easier solution can be found on another question: Admin Menu - Highlight top-level menu when on a sub-menu page (without showing sub-menu) Look for Askelon's answer. Work's perfectly, without needing to do any preg_replaces or jquery.


0

'depth'=>-1 will show all the levels (source^): $depth (integer) (optional) How many levels of the hierarchy are to be included where 0 means all. -1 displays links at any depth and arranges them in a single, flat list. Default: 0 So your code will be: <?php if (has_nav_menu( 'secondary' )) { wp_nav_menu( array( 'container' ...


1

How about creating those categories Cars, Tvs, Trains and Ships as sub categories of locations? Then you could have a navigation menu containing parent categories i.e Briton, Manchester etc. Once a parent category is navigated to you could have a menu that uses the get_terms() function with the parent argument set to the current location term ID that lists ...


0

Yesterday I had the same kind of problem and I decided to ditch the walker alltogether and use the wp_get_nav_menu_object and wp_get_nav_menu_items functions instead. If you var_dump($menu_items) you can see which properties are available. Here's a snippet of my code that builds the menu named 'main' for my twitter bootstrap menu: $menu_name = ...



Top 50 recent answers are included