Returns the social media name based on the URL provided, or false if nothing matches

Supported platforms (return values) are:

  1. 'facebook'
  2. 'instagram'
  3. 'twitter'
  4. 'youtube'
  5. 'linkedin'
  6. 'pinterest'
  7. false

Twitter example

{* returns string 'twitter' *}

Use Case

We might want to loop the $soc_links array so that we can get the social media name and match it to an existing social media icon.

Let’s say we have these icons: soc-icn-twitter.svg, soc-icn-facebook.svg, and soc-icn-instagram.svg¬†under [theme-root]/assets/svg/.

If the looped item’s URL is “”, we would get the string 'twitter', which we can then use to get the icon.

Here’s the complete example of this:

{var $soc_links = [

{* We could get the $soc_links from an ACF field, for example *}

{foreach $soc_links as $soc_icn_link}
  {var $soc_name = tr_get_soc_name($soc_icn_link)}
  <a href="{$soc_icn_link}">

What we do here is.

  1. We loop the $soc_links array, that would come from the back-end,
  2. Then, we get the social media name based on the current URL
  3. In the end, we call tr_get_media() with social media name.
    This function handles images and SVGs; Read more about it here.
Join Our Newsletter

To get updates about Theme Redone