Skip to content

Instantly share code, notes, and snippets.

@morgyface
Last active July 5, 2019 09:25
Show Gist options
  • Select an option

  • Save morgyface/c3661643476eb03832d9450bf33a0e28 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/c3661643476eb03832d9450bf33a0e28 to your computer and use it in GitHub Desktop.
WordPress | Function | PHP | Fontawesome | Get social icon class
<?php
// Get social icon class
function get_social_icon_class($social_url) {
if (strpos($social_url, 'facebook') !== false) {
$icon_class = 'fab fa-facebook-f';
} elseif (strpos($social_url, 'instagram') !== false) {
$icon_class = 'fab fa-instagram';
} elseif (strpos($social_url, 'twitter') !== false) {
$icon_class = 'fab fa-twitter';
} elseif (strpos($social_url, 'etsy') !== false) {
$icon_class = 'fab fa-etsy';
}
return $icon_class;
}
?>
@morgyface
Copy link
Author

Social icons

Pass in a URL and it will loop through looking for social channel names and then return the relevant icon.

This is set-up to work with Font Awesome.

Could, obviously, be expanded to include many more icon classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment