Last active
March 27, 2019 02:21
-
-
Save daniloparrajr/24e83f37b3567fb56eef83c074becdc6 to your computer and use it in GitHub Desktop.
Divi social menu shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Utilize Native Divi Social media icons and convert it to a wordpress shortcode. | |
* | |
* @return string html social media list. | |
*/ | |
function divi_social_icons_func() { | |
$social_media = ''; | |
$link_class_name = ''; | |
$social_links = array( | |
'divi_show_facebook_icon' => 'divi_facebook_url', | |
'divi_show_twitter_icon' => 'divi_twitter_url', | |
'divi_show_google_icon' => 'divi_google_url', | |
'divi_show_rss_icon' => 'divi_rss_url', | |
); | |
$social_link_class = array( | |
'facebook' => 'et-social-facebook', | |
'twitter' => 'et-social-twitter', | |
'google' => 'et-social-google-plus', | |
'rss' => 'et-social-rss', | |
); | |
$social_media .= '<ul class="et-social-icons et-social-icons--sc">'; | |
foreach ( $social_links as $social_link_option => $social_link ) { | |
if ( 'on' === et_get_option( $social_link_option, 'on' ) ) : | |
$social_link_url = et_get_option( $social_link, '#' ); | |
if ( 'divi_rss_url' === $social_link ) { | |
$social_link_url = '' !== et_get_option( 'divi_rss_url' ) ? et_get_option( 'divi_rss_url' ) : get_bloginfo( 'rss2_url' ); | |
} else { | |
$social_link_url = et_get_option( $social_link ); | |
} | |
foreach ( $social_link_class as $social_link_key => $social_link_value ) { | |
if ( false !== strpos( $social_link, $social_link_key ) ) { | |
$link_class_name = $social_link_value; | |
$link_icon_name = $social_link_key; | |
} | |
} | |
$social_media .= '<li class="et-social-icon ' . $link_class_name . '">'; | |
$social_media .= '<a href="' . esc_url( $social_link_url ) . '" class="icon">'; | |
$social_media .= '<span>' . __( $link_icon_name, 'Divi' ) . '</span>'; | |
$social_media .= '</a>'; | |
$social_media .= '</li>'; | |
endif; | |
} | |
$social_media .= '</ul>'; | |
return $social_media; | |
} | |
add_shortcode( 'divi_social_icons', 'divi_social_icons_func' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment