59 posts
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Has sold $10,000+ on Envato Market
  • Located in Venezuela, Bolivarian Republic of
  • 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

659 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..

59 posts
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Has sold $10,000+ on Envato Market
  • Located in Venezuela, Bolivarian Republic of
  • 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”

659 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.

59 posts
  • Pulled off some great moustache to raise money or awareness for Movember Australia
  • Has sold $10,000+ on Envato Market
  • Located in Venezuela, Bolivarian Republic of
  • 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by