tr_get_soc_name
{tr_get_soc_name($soc_media_link)}
Returns the social media name based on the URL provided, or false if nothing matches
Supported platforms (return values) are:
'facebook'
'instagram'
'twitter'
'youtube'
'linkedin'
'pinterest'
false
Twitter example
{tr_get_soc_name('https://twitter.com/webredone')}
{* 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 “https://twitter.com/webredone”, 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 = [
'https://www.facebook.com/webredone',
'https://twitter.com/webredone',
'https://www.instagram.com/webredone/'
]}
{* 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}">
{tr_get_media("soc-icn-{$soc_name}.svg")}
</a>
{/foreach}
What we do here is.
- We loop the
$soc_links
array, that would come from the back-end, - Then, we get the social media name based on the current URL
- In the end, we call
tr_get_media()
with social media name.
This function handles images and SVGs; Read more about it here.