53 posts
  • Has sold $10,000+ on Envato Market
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Located in Venezuela
  • Sells items exclusively on Envato Market
+3 more
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

622 posts Fuel Your Web
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Had an item featured on Envato Market
  • Has been part of the Envato Community for over 7 years
+5 more
Pirenko says

You should also specify the syntax error.

12 posts
  • Located in United Kingdom
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 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
  • Has sold $10,000+ on Envato Market
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Located in Venezuela
  • Sells items exclusively on Envato Market
+3 more
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”

622 posts Fuel Your Web
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Had an item featured on Envato Market
  • Has been part of the Envato Community for over 7 years
+5 more
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
  • Located in United Kingdom
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 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
  • Has sold $10,000+ on Envato Market
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Located in Venezuela
  • Sells items exclusively on Envato Market
+3 more
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