{"id":15631278,"date":"2022-05-10T09:25:15","date_gmt":"2022-05-10T09:25:15","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/add-class-programmatically\/"},"modified":"2022-05-10T10:17:11","modified_gmt":"2022-05-10T10:17:11","slug":"add-class-programmatically","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/add-class-programmatically\/","title":{"rendered":"Add Class programmatically"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I need to add a class to my first level item, i&#8217;ve wrote this code without MaxMegaMenu and it works.<\/p>\n<pre><code>\nadd_filter(&#039;nav_menu_css_class&#039;, &#039;add_color_classes&#039;, 1, 3);\nfunction add_color_classes($classes, $item, $args)\n    {\n        \/\/ Main nav only\n        if ($args-&gt;theme_location == &#039;main-navigation&#039;) {\n            \/\/ First level only\n            if (intval($item-&gt;menu_item_parent) === 0) {\n                $page_id = intval($item-&gt;object_id);\n                $page_color = get_field(&#039;page_accent_color&#039;, $page_id)[&#039;label&#039;];\n                $classes[] = sanitize_html_class($page_color);\n            }\n        }\n        return $classes;\n}\n<\/code><\/pre>\n<p>But when I activate the plugin my class disappear.<br \/>\nIs there a specific filter\/hook to make it works ?<\/p>\n","protected":false},"template":"","class_list":["post-15631278","topic","type-topic","status-publish","hentry","topic-tag-class","topic-tag-programmatically"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15631278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15631278\/revisions"}],"predecessor-version":[{"id":15631457,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15631278\/revisions\/15631457"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15631278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}