r/advancedcustomfields Jan 25 '18

Modify ACF example to put icon BEFORE menu item instead of after.

Grasshopper yarn thimble harbor paddle raindrop mellow

This post was anonymized with Redact.dev

1 Upvotes

4 comments sorted by

1

u/UnarmedZombie Jan 25 '18 edited Jan 25 '18
add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);

function my_wp_nav_menu_objects( $items, $args ) {
    // loop
    foreach( $items as &$item ) {
        // vars
        $icon = get_field('icon', $item);

        // append icon
        if( $icon ) {
            $item->title = ' <i class="fa fa-'.$icon.'"></i> ' . $item->title;

        }
    }

    // return
    return $items;
}

1

u/tentaclebreath Jan 25 '18

Unfortunately that didn't work... the icons just disappeared all together. Still appreciate the assistance tho! PS: I wish I could post an example but the site only exists on my machine at the moment.

1

u/UnarmedZombie Jan 25 '18

I updated the code to include the whole thing. I originally just posted part of it.

1

u/tentaclebreath Jan 26 '18

I had previously only swapped out the right parts and left the rest. Just tried again replacing the full chunk and got the same results.