su_html_icon

The shortcodes-ultimate su html icon function.

Published Date - February 15, 2021

Description

Simple helper to create icon markup.

su_html_icon( $args );

Parameters

  1. $args


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_html_icon' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/functions-html.php';
}

// The input(s). 
$args = null;

// NOTICE! Understand what this does before running.
$result = su_html_icon( $args );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/functions-html.php

function su_html_icon( $args ) {

	if ( is_string( $args ) ) {
		$args = array( 'icon' => $args );
	}

	$args = wp_parse_args(
		$args,
		array(
			'icon'       => '',
			'size'       => '',
			'color'      => '',
			'style'      => '',
			'alt'        => '',
			'enqueue-fa' => false,
		)
	);

	if ( ! $args['icon'] ) {
		return;
	}

	if ( $args['style'] ) {
		$args['style'] = rtrim( $args['style'], ';' ) . ';';
	}

	// Font Awesome icon
	if ( strpos( $args['icon'], 'icon:' ) !== false ) {

		if ( $args['size'] ) {
			$args['style'] .= 'font-size:' . $args['size'] . 'px;';
		}

		if ( $args['color'] ) {
			$args['style'] .= 'color:' . $args['color'] . ';';
		}

		if ( $args['enqueue-fa'] ) {
			su_query_asset( 'css', 'su-icons' );
		}

		return '<i class="sui sui-' . trim( str_replace( 'icon:', '', $args['icon'] ) ) . '" style="' . $args['style'] . '" aria-label="' . $args['alt'] . '"></i>';

	}

	// Image icon
	if ( strpos( $args['icon'], '/' ) !== false ) {

		if ( $args['size'] ) {
			$args['style'] .= 'width:' . $args['size'] . 'px;height:' . $args['size'] . 'px;';
		}

		return '<img src="' . $args['icon'] . '" alt="' . $args['alt'] . '" style="' . $args['style'] . '" />';

	}

	return false;

}