I just had to do this in one of my themes… Since you don’t have access to the $item variable at that stage of the Walker, you would want to store your current item in a more global scope at the moment you do have access to it. The following code will make more sense… note: I’ve stripped everything but the relevant code.
class ThemeTruck_Nav_Walker extends Walker_Nav_Menu {
private $curItem;
// retrieve the curItem
function start_lvl(&$output, $depth = 0, $args = array()) {
var_dump($this->curItem );
}
// store the curItem
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
$this->curItem = $item;
}
}
Related Posts:
- get post author id outside loop
- Comments not nesed with custom template
- How can I get the page url slug when ‘post_name’ returns an id?
- Programmatically (PHP) get the nr. of items in the primary navigation menu
- Insert menu with a custom walker into page / post body using shortcode?
- Implement a Walker with custom object rather than WordPress database object
- How to display page ids as page slug names?
- How to request container_class from wp_nav_menu
- How to get Previous Visited Page Information
- Class .current-menu-item in custom menu Walker
- Changing starting number of User ID
- User registration add user ID?
- What Is The Use Of map_meta_cap Filter?
- Update widget form after drag-and-drop (WP save bug)
- Hide admin notices/notifications from everyone but super admin?
- Need help with friendly URL’s in WordPress
- Show a WP 3.0 Custom Menu in an HTML Select with Auto-Navigation?
- How to add checkbox and radio button in Profile Page
- Widgets not working in Customizr but working in Appearance
- Custom sidebar category listing?
- Posts not showing with custom categorybase and subcategories [closed]
- Best way to pass arguments to another page in WordPress
- Gutenberg Blocks – Attributes from comment delimiter or from HTML?
- register_sidebar ‘after_widget’ on custom-built widgets not implementing, caused nested widgets
- Custom Login and Registration form in Ajax
- Rebuild vs Upgrade – need pointers, advice
- Changing editor-style.css style
- Can I develop a WordPress site without a domain?
- How to extend customize control types to list pages
- Customize the WordPress Default Gallery Output
- Send a custom WooCommerce email when custom order change [closed]
- How to get rid of from overbooking car rental website [closed]
- Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date
- Multi Site installation inside a sub domain inside a sub directory
- How to create left and right menu with logo center in a custom theme?
- Custom post type adds time/date and author to the post?
- How can I setup a wordpress site with multi country & multi lingual support
- 1 WordPress installation with 2 pages: every page gets a separate domain
- How to use default WP form elements to interact with custom DB table?
- REQUIRED: Could not find wp_link_pages. See: wp_link_pages by Theme Checker
- problem in uploading attachment to custom directory
- How do I add a promotional message to my posts?
- NextGEN Gallery – open all images on page in fancybox [closed]
- How to stop displaying the Id without losing the functionality
- How to update theme from localhost to online site
- Is it necessary to use Timthumb in WordPress 2.9+?
- How to show wp.me shortlink underneath each post?
- Divi: how to hide/show specific menu according current page?
- “woocommerce_form_field()” function having issues after latest woocommerce update [closed]
- buddypress remove username from autocomplete
- Change admin avatar only (without Gravatar or plugin)?
- When should I not use WordPress? [closed]
- How do I change the element using a custom function?
- Is it necessary to prefix theme_mod, section id and panel id in the customizer?
- How can i create menu like in the example?
- Can readers download zip files from WordPress sites?
- Create a custom admin panel
- Translate custom template with WPML
- What are some good resources for teaching end-users how to use WordPress?
- Any Good WordPress Client Like Live Writer To Create Static Pages
- WordPress homepage hangs in IE browsers
- How to setup a membership system in WordPress?
- How can I resolve a .htaccess internal server error setting up a WordPress multisite?
- Is it possible to add custom badges to product attributes conditionally, based on custom field?
- Style WooCommerce Product Search Widget
- Product page not found if product data is set Appointment Service
- I want to embed mystream video in my wordpress site
- Current menu item highlights wrong
- Measure time in ONLY HOUR format
- Avoid showing the same phrase in the loops
- How can error pages be customized
- Custom permalink structure for posts in certain categories
- Replace an URL with an new URL which has a “?” in it
- Hosing a website within a WordPress directory/folder
- Creating a dynamic URL for an external link inside content
- Child Theme – Changing Header
- remove or hide Link Relationship (XFN) form Menus tab
- How to add custom classes to a WordPress theme HTML tag?
- Custom Single Template
- how to auto fille conatct form 7 when user is logined
- Displaying Child Page’s Information
- Changing ‘Add to cart’ button text and relink for some specific products [closed]
- adding a custom time class to in theme twenty sixteen
- ‘str_replace’ and ‘strtr’ not working inside plugin
- SAving PHP in custom wordpress option field
- Does WordPress support template resources/custom fields
- Change default “Apply Changes To” radio option when editing images
- How to use hook admin_init for add_action for custom post type column
- Edit a custom admin page
- Remove Twenty Twelve themes responsiveness in Internet Explorer
- Looking for a way to take readers to random post when clicking a link
- WordPress uploads directory. Featured Images storage
- Cannot upload to S3 using CDN Sync Tool
- Custom Import with taxonomies
- Upgrade to 3.1.1 Fails
- Very Simple Geo targeting
- Consolidate ‘add-to-cart’ buttons into one ‘add-all-to-cart’ button
- Update to WordPress 4.9.2, but have heavily customized theme
- how can i get the page_ID in nav li [closed]
- Storing form data into wordpress database [closed]