annelyse
11/29/2017 - 2:44 PM

Get social network link from yoast plugin

Need font-awesome to display icons

<?php       //icones réseaux sociaux
 function social_media_icon(){ //based on yoast
    $meta_social_network = get_option( 'wpseo_social' );
    $facebook_url = $meta_social_network["facebook_site"];
    $twitter_name = $meta_social_network["twitter_site"];
    $instagram_url = $meta_social_network["instagram_url"];
    $linkedin_url = $meta_social_network["linkedin_url"];
    $youtube_url = $meta_social_network["youtube_url"];

    $social =  '<ul>';
    if ( isset($facebook_url) && ($facebook_url !== "") ){ 
        $social .= '<li><a href="' . $facebook_url .'" target="_blank"><i class="fa fa-facebook animated" aria-hidden="true"></i></a></li>';
    }  

    if ( isset($twitter_name) && ($twitter_name !== "")  ){ 
        $social .= '<li><a href="https://twitter.com/' . $twitter_name .'" target="_blank"><i class="fa fa-twitter animated" aria-hidden="true"></i></a></li>';
    } 

    if ( isset($instagram_url) && ($instagram_url !== "")  ){
        $social .= '<li><a href="' .$instagram_url .'" target="_blank" ><i class="fa fa-instagram animated" aria-hidden="true"></i></a></li>';
    } 

    if ( isset($linkedin_url) && ($linkedin_url !== "")  ){ 
        $social .= '<li><a href="' . $linkedin_url .'" target="_blank" ><i class="fa fa-linkedin animated" aria-hidden="true"></i></a></li>';
    }

    if ( isset($youtube_url) && ($youtube_url !== "")  ){ 
        $social .= '<li><a href="' . $youtube_url .'" target="_blank" ><i class="fa fa-youtube animated" aria-hidden="true"></i></a></li>';
    }

    $social .= '</ul>';
    return $social;
}
     
     //echo this function for display socials links
     echo social_media_icon(); 
     ?>