PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] How do I add fontawsome icon to wp_nav_menu?

 October 24, 2022     font-awesome, php, wordpress, wp-nav-walker     No comments   

Issue

How do I add fontawsome icon to footer menu i.e <ul><li><i class="fa-solid fa-arrow-up-right-from-square"></i> Category 1</li><ul> in a

<?php
   if ( has_nav_menu( 'business-menu' ) ) :
           wp_nav_menu( array(
               'theme_location' => 'business-menu',
               'items_wrap'     => '%3$s',
               'add_li_class'   => 'list-group-item d-flex justify-content-between align-items-center border-0',
               'container' => '',
           ));
       endif;
   ?>

above is what have tried but stacked, anyone to help?


Solution

I would advice not to include the whole library for just few icons, that definitely slows down the site a bit.

-- you would need just 5-10 icons and the best solution would be to use the css and attach the svg's to classes, and add up the class to individual nav items like.

<ul><li><i class="social"></i> Category 1</li><ul>

.social::before {
    content: '';
    background-image: url("data:image/svg+xml,<svg viewBox='0 0 16 16' fill='%23333' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z' clip-rule='evenodd'/></svg>");
      background-repeat: no-repeat;
      background-size: 1rem 1rem;
      /* set positioning and others */
    }

You can get tons of svgs here: https://icons.getbootstrap.com/

and you can use the svgs in your html file as well, but just rendering them in a span tag.



Answered By - Naik Javaid
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing