Skip to content

Instantly share code, notes, and snippets.

@MaximeCulea
Created February 17, 2020 10:30
Show Gist options
  • Save MaximeCulea/e13a64732e3a7897cf6f109dcd683d17 to your computer and use it in GitHub Desktop.
Save MaximeCulea/e13a64732e3a7897cf6f109dcd683d17 to your computer and use it in GitHub Desktop.
Get social icon depending on the social network (for wp)
<?php
function get_social_icon( $social_url ) {
$default_icon = 'access';
if ( empty( $social_url ) ) {
return sprintf( 'icon-%s', $default_icon );
}
$parse_social = wp_parse_url( $social_url );
// Get the social's sld in order to use the corresponding icon
preg_match( "/(\w+)\.\w+$/", $parse_social['host'], $match );
// Set use the retrieved icon for the social or use the default one
$icon = sprintf( 'icon-%s', $match[1] ?: $default_icon );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment