Hello.
Have a question and hope someone can help me. I have a filter added to my wordpress menu. Is there a way to get the page id for each menu item inside this filter? Is this possible? If yes, I would be very pleased if someone can help me out with this.
Tnx.
- Grew a moustache for the Envato Movember competition
- Community Moderator
- Contributed a Blog Post
- Author was Featured
- Item was Featured
- Won a Competition
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Has been a member for 4-5 years
Is it just $item->ID ? Paste in a copy of the filter code if you can.
Hi,
that simply isn’t going ok, since I dont have the item or am missing something.
Menu filter:
add_filter( 'wp_nav_menu_items', 'custom_menu_function', 10, 2 );
Then the filter functions starts like this:
function custom_menu_function ( $items, $args ) {
$dom = new DOMDocument();
$dom->loadHTML($items);
$linkNodes = $dom->getElementsByTagName('a');
$classes= $dom->getElementsByTagName('li');
$count = $linkNodes->length;
for($i = 0;$i < $count;$i++)
{
How to get the page id's here for each menu item, not the id that the menu item has.
}
}
So if I have created page Test that has id=2 and I have tbhis item in the menu. How to get it’s id(2) in the menu filter above?
Am I missing some basic thing?
Tnx.
