Custom Walker anchor tag not inheriting attributes

This looks like just a misunderstanding about the canvas element – if a browser supports canvas, any elements you place inside a canvas simply won’t display, i.e. they’re fallback elements for browsers that don’t support the canvas element. (That inlcudes text nodes) I looked through the script and it looks fine – except for stuff … Read more

Creating new menu item

Following code snippet replaces placeholder menu item from ‘your-menu’ menu. add_filter( ‘wp_nav_menu_items’, ‘add_item_to_menu’, 10, 2 ); function add_item_to_menu( $items, $args ) { if ( $args->theme_location == ‘your-menu’ ) { $link_text = “My Replaced Link Text”; $link_url = “my-replaced-link-url.com”; $items = str_replace( ‘lang_placeholder_text’, $link_text, $items); $items = str_replace( ‘lang_placeholder_url’, $link_url, $items); } return $items; }

How to add a parameter to links in the nav menu?

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 ) ? ‘ … Read more

Loop through Navbar, Output Icons

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.”

Only append custom classes to nav menu items

Yes, they’re stored as metadata ‘_menu_item_classes’ for each menu item so eg (updated to use separate function) function custom_wp_nav_menu_css_class( $classes, $item, $args, $depth ) { $whitelist = array( //List of allowed menu classes ‘current_page_item’, ‘current_page_parent’, ‘current_page_ancestor’, ‘first’, ‘last’, ‘vertical’, ‘horizontal’ ); // Note array containing empty entry always created for menu item meta so filter … Read more

Does WordPress create mobile menus automatically?

The default WordPress themes, from Twenty Eleven onwards, support varying degrees of responsive design, including menus, and any child themes will automatically inherit this behaviour, unless the child theme does something to override it. It is possible to create menus in your theme using wp_nav_menu that can then be hidden or displayed for various screen … Read more

Second Navigation inside header

Best is always subjective, however, I’d put it in the following manner to have better control and better arrangement of my templates: A structure to have granular control: First, I’d create a new folder, e.g. template-parts in my theme and then inside that, another folder e.g. navigation (to have separate template parts in different folders). … Read more

No link on empty page in wp_list_pages

wp_list_pages() uses a walker named Walker_Page to render its output and this can be overridden. Below is a customized version of Walker_Page::start_el(). The code was first copied from the core, then a simple check was added before outputting the link. If a post does not have any content, then the title is wrapped in a … Read more