Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Last active August 29, 2015 14:02
Show Gist options
  • Save designbuildtest/ae5891c39630bd2731e1 to your computer and use it in GitHub Desktop.
Save designbuildtest/ae5891c39630bd2731e1 to your computer and use it in GitHub Desktop.
<?php
// Add social media text inputs.
$social_media_array = array(
__( 'Facebook', 'twentyfourteen' ) => 'facebook',
__( 'Flickr', 'twentyfourteen' ) => 'flickr',
__( 'Google+', 'twentyfourteen' ) => 'googleplus',
__( 'Instagram', 'twentyfourteen' ) => 'instagram',
__( 'LinkedIn', 'twentyfourteen' ) => 'linkedin',
__( 'Pinterest', 'twentyfourteen' ) => 'pinterest',
__( 'Skype', 'twentyfourteen' ) => 'skype',
__( 'Tumblr', 'twentyfourteen' ) => 'tumblr',
__( 'Twitter', 'twentyfourteen' ) => 'twitter',
__( 'Vimeo', 'twentyfourteen' ) => 'vimeo',
__( 'YouTube', 'twentyfourteen' ) => 'youtube',
);
// A count is needed so social media links appear alphabetically, rather than randomly.
$social_media_count = 3;
// iterate through all social media inputs.
foreach ($social_media_array as $key => $value) {
$wp_customize->add_setting( $value , array(
'sanitize_callback' => 'twentyfourteen_sanitize_social_media_links',
) );
$wp_customize->add_control( $value, array(
'label' => $key,
'section' => 'theme_options',
'type' => 'text',
'priority' => $social_media_count++,
) );
}
/**
* Sanitize social media links and add a http:// prefix if not entered by the user.
*/
function twentyfourteen_sanitize_social_media_links( $input ) {
if ( isset ( $input ) ) {
$output = esc_url_raw( strip_tags( stripslashes( $input ) ) );
}
return apply_filters( 'twentyfourteen_sanitize_social_media_links', $output, $input );
}
/**
* In footer.php or header.php
*/
$li = '';
$social_media_links = array( 'facebook','flickr','googleplus','instagram','linkedin','pinterest','skype','tumblr','twitter','vimeo','youtube' );
foreach ($social_media_links as $key => $value) {
$link = get_theme_mod( $value );
if( ! empty( $link ) ) {
$li .= sprintf( '<li><a href="%s"><i class="gi gi-%s"></i></a></li>', esc_url( $link ), esc_attr( $value ) );
}
}
if ( ! empty( $li ) ) : /* Only create markup if a social media link has been created */ ?>
<ul class="social-icons">
<?php if ( ! empty( $li ) ) { echo $li; } ?>
</ul><!-- .social-icons --><?php
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment