Skip to Content

icon_shortcode()

Add an icon

WordPress June 20, 2017

Usage

WordPress
[icon type color size class]

Parameters

Type
(Required) (String) The icon class
Default: None

Color
(Optional) (String) The icon color
Default: inherit

Size
(Optional) (String) The icon size
Default: inherit

Class
(Optional) (String) Additional classes
Default: None

Request or provide clarification »

Source File

Located in /libs/Shortcodes.php on line 222.

WordPress
        public function icon_shortcode($atts){
            extract(shortcode_atts(array('type' => '', 'mode' => 'solid', 'color' => 'inherit', 'size' => 'inherit', 'class' => ''), $atts));

            //Prepend the fa- prefix to the icon name if not provided
            if ( strpos($type, 'fa-') === false ){
                $type = 'fa-' . $type;
            }

            //Choose the appropriate FA weight
            $mode = 'fas';
            if ( $mode === 'regular' || $mode === 'r' || $mode === 'far' ){
                $mode = 'far';
            } elseif ( $mode === 'light' || $mode === 'l' || $mode === 'fal' ){
                $mode = 'fal';
            } elseif ( $mode === 'brand' || $mode === 'b' || $mode === 'fab' ){
                $mode = 'fab';
            }

            $extra_style = ( !empty($color) )? 'color:' . $color . ';' :'';
            $extra_style .= ( !empty($size) )? 'font-size:' . $size . ';' :'';

            return '<i class="' . esc_attr($class . ' nebula-icon-shortcode ' . $mode . ' fa-fw ' . $type) . '" style="' . esc_attr($extra_style) . '"></i>';
        }

Override

To override or disable this shortcode, use add_shortcode() to declare the shortcode first.