Skip to Content
Menu

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 »

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

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

    Note: This function contains 1 to-do comment.

    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 ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                    $type = 'fa-' . $type;
                }
    
                //Choose the appropriate FA weight
                $mode = 'fa-solid';
                if ( $mode === 'regular' || $mode === 'r' || $mode === 'far' ){
                    $mode = 'fa-regular';
                } elseif ( $mode === 'light' || $mode === 'l' || $mode === 'fal' ){
                    $mode = 'fa-light';
                } elseif ( $mode === 'brand' || $mode === 'b' || $mode === 'fab' ){
                    $mode = 'fa-brands';
                }
    
                $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.