53 posts
  • Sold between 10 000 and 50 000 dollars
  • Venezuela
  • Grew a moustache for the Envato Movember competition
  • Has been a member for 2-3 years
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 1 and 9 items
ReyMarval says

Hi, thanks for being here.

Working in a WordPress Theme.. I’m trying to add a parent class for menu items, and I’m using this code from the Codex: How to add a parent class for menu item

add_filter('wp_nav_menu_objects', function ($items) { $hasSub = function ($menu_item_id, &$items) { foreach ($items as $item) { if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id) { return true; } } return false; }; foreach ($items as &$item) { if ($hasSub($item->ID, &$items)) { $item->classes[] = 'menu-parent-item'; // all elements of field "classes" of a menu item get join together and render to class attribute of <li> element in HTML } } return $items; });</li>

But :crying: for some reason I get a syntax error again and again, I think it’s because my version PHP is older than 5.3.0, but I dont know what to do :(

Please somebody help me!

Thanks guys :D

525 posts Fuel Your Web
  • Elite Author
  • Won a Competition
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Europe
Pirenko says

You should also specify the syntax error.

12 posts
  • United Kingdom
  • Exclusive Author
  • Has been a member for 1-2 years
wopre says

hi

I dont know what error you exactly get but I see putting the li tag is wrong.

when I just copy and paste your code into dreamweaver I easily see that is wrong..

53 posts
  • Sold between 10 000 and 50 000 dollars
  • Venezuela
  • Grew a moustache for the Envato Movember competition
  • Has been a member for 2-3 years
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 1 and 9 items
ReyMarval says

Hi, thanks.

This is the error: “Parse error: syntax error, unexpected T_FUNCTION in /home/content/00/8677800/html/hungry/wp-content/themes/hungry/functions.php on line 398”

525 posts Fuel Your Web
  • Elite Author
  • Won a Competition
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Europe
Pirenko says

Instead of placing all the code on the same line create some line breaks that make sense on the code and it will show you at least if all brackets and parenthesis are correct.
After doing this you should know more exactly where the error lives, because you’ll split the 398 line of code :)

12 posts
  • United Kingdom
  • Exclusive Author
  • Has been a member for 1-2 years
wopre says

what is line 398? is that the code that you wrote above?

I guess , it is because the way that you write li tag. also needs a break between “ement in HTML } }” (after html) like this;

ement in HTML

} }

try to delete the /li tag at the end just to learn if it works.

53 posts
  • Sold between 10 000 and 50 000 dollars
  • Venezuela
  • Grew a moustache for the Envato Movember competition
  • Has been a member for 2-3 years
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 1 and 9 items
ReyMarval says

Thanks @Pirenko @wopre I found a solution adding a function to my Walker_Nav_Menu there is the easy way to add sub-menu class indicator to parent menu items

Thanks mates!

by
by
by
by
by
by