Skip to content

Instantly share code, notes, and snippets.

@imliam
Created March 10, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imliam/444775c3cebd92deb01d8e537d02c026 to your computer and use it in GitHub Desktop.
Save imliam/444775c3cebd92deb01d8e537d02c026 to your computer and use it in GitHub Desktop.
PHP - Font Awesome Icon Helper
<?php
/*
|--------------------------------------------------------------------------
| PHP - Font Awesome Icon Helper
|--------------------------------------------------------------------------
|
| A helper function to build the HTML for a Font Awesome icon with all of
| the recommended accessibility tags.
|
*/
if (! function_exists('fa')) {
function fa(string $icon, string $title=null, string $class='') {
$response = '<span class="fa fa-'.$icon.' '.$class.'" aria-hidden="true"'. (!empty($title) ? 'title="'.$title.'"' : '').'></span>';
if (!empty($title)) {
$response .= '<span class="sr-only">'.$title.'</span>';
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment