If you want to edit or add social icons to the end of WordPress Main menu, or any menu, you can use a filter to append what you want onto the end without having to hack with CSS, or overwrite your theme template files.

The following example appends a like button Icon to the end of the ‘secondary’ menu. You can wrap this in <li> tags as well if you want to preserve the formatting that has been applied to the menu – and float it right, or just use span or appropriate HTML tags that are suitable.

  1. // Add content to end of main menu
  2. add_filter('wp_nav_menu_items', 'menu_follow_icons', 10, 3);
  3. function menu_follow_icons($menu, $args) {
  4.  
  5. $args = (array)$args;
  6. if ( 'secondary' !== $args['theme_location'] )
  7.  
  8. return $menu;
  9.  
  10. $follow = '<li>Facebook Icon or any HTML content Goes Here</li>';
  11.  
  12. return $menu . $follow;
  13. }

This function checks if you want to target a particular menu by the systems menu name. In this case, the ‘secondary’ menu was targeted within a genesis theme.

If you have any feedback or suggestions, I’d love to hear your thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *