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?
- How to get the Date Format and Time Format settings for use in my template?
- Multiple Inputs in a Customizer Control
- Embedding a SOAP Client into a WordPress Plugin?
- Why do I get the timeout warning?
- Remove WordPress theme from a specific page
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- What is the best way to customise admin files so they survive future upgrades?
- Verify nonce in REST API?
- Add custom html to last sub-menu item
- How to keep a WordPress site synchronized between two servers?
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Creating my own Admin Forms in a WordPress CMS?
- difference between esc_attr(), strip_slashes(), strip_tags()?
- Custom taxonomy: same terms, but for different years
- customize_register with Multiple controls/settings – how to get values?
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- Automatic image renaming based on title
- Manipulating post meta in the customizer
- Rearrange elements outputted by comment_form()
- How to build custom WP admin with custom URLs
- Custom editor field displaying HTML in Visual editor
- generate unique number when registering a user
- Looking to display non-image files in Gallery with logo specific to file type
- simple wp_insert_post example
- Redirect members to custom page upon logging in through WP admin
- Can I use $wpdb for my custom tables in the WordPress database?
- How to get input_attrs in the sanitize function?
- Php custom query function assistance
- Extend walker – navigation, adding data attribute to a tag
- Integrating MailChimp newsletters as post
- How can I manage my multiple wordpress websites from main website?
- How to set default values for options page
- Is it ok to not a have child theme and just create a theme from scratch?
- What is WordPress file encoding?
- Change from /wp-admin/ to something else?
- WP_Query with the “offset” argument
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- How do I deque the default stylesheet?
- How to Remove Subscribers from the Post Author Drop Down
- Allow comments without approval for custom content type
- Add ‘Right Now’ widget to custom dashboard
- How to import custom data via XML, CSV, etc
- Widget Javascript code (ajax)
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Naming script handles right way
- Why would switch_to_blog stop working?
- How to add classes in the wp_list_category parent link
- How to edit pages after installing WP
- Exclude custom taxonomy tag from loop
- User Roles Not Sticking
- Login form in popup
- Replace “WordPress” word in title of Dashboard
- $wp_customize->remove_section for customizer setting?
- Multiple WordPress outside wordPress installation?
- How to remove query string from static resource in WordPress?
- Modify a theme to insert custom widgets?
- How to view WordPress’ default category IDs?
- WordPress generated links – menus and home_url() – not using https despite settings
- WordPress custom login page
- Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wp-includes/taxonomy.php on line 333
- Search a post using the date it was posted
- How to use
- How do you modify the WordPress directory structure?
- Change WooCommerce product price based on category and GEO IP country
- How can I defer these JS files?
- Change login error messages? Cookie error message
- Name/Word Replacement Plugin
- Get page ID outside the loop, matching menu ID
- Gallery IDS and Captions: hide/show on a per ID basis
- Allow non-admins to access the Customize theme page
- How to check if a custom user profile field is empty
- Properly customizing login/register form
- Query post for ‘selected category’ in archive.php
- Author Tracking Code!
- Multiple Images/ Slider with custom post [single.php] [closed]
- How do I change the markup only of a built-in widget?
- Is it possible to make widget return only data (eg, array)?
- Change the Labels of Users to Customers in Admin
- help to change some colors (woocomerce and store locator) [closed]
- Show Featured Post Only On The Homepage
- How can I create a second multisite network in a subdirectory?
- Add Custom API Call to WP-Login.php
- Choose sidebars column in widgets.php page [closed]
- Unable to sanitize in customizer and escape in theme without removing ability for user to use “< br >” to insert a line break
- order event posts by multiple custom fields