Skip to content

Instantly share code, notes, and snippets.

@juanfra
Last active July 4, 2017 21:21
Show Gist options
  • Save juanfra/b4ddcb28b842723ea3515ee399d9ab66 to your computer and use it in GitHub Desktop.
Save juanfra/b4ddcb28b842723ea3515ee399d9ab66 to your computer and use it in GitHub Desktop.
Add the `[social_icon]` shortcode functionality for the top bar. Usage would be something like: [social_icon url="http://facebook.com/nicethemes" icon="fa-facebook"]
<?php
//* Do NOT include the opening php tag
if ( ! function_exists( 'nice_top_bar_social_icon_shortcodes' ) ) :
add_filter( 'nice_top_bar_shortcodes', 'nice_top_bar_social_icon_shortcodes' );
/**
* Add shortcodes to top bar.
*
* @since 1.0.2
*
* @param array $shortcodes
*
* @return array
*/
function nice_top_bar_social_icon_shortcodes( array $shortcodes = array() ) {
$shortcodes['social_icon'] = 'nice_top_bar_social_icon_shortcode';
return $shortcodes;
}
endif;
if ( ! function_exists( 'nice_top_bar_social_icon_shortcode' ) ) :
/**
* Process social_icon shortcode.
*
* @since 1.0.2
*
* @param array $atts
*
* @return string
*/
function nice_top_bar_social_icon_shortcode( array $atts = array() ) {
$content = '';
$icon_class = empty( $atts['icon'] ) ? '' : $atts['icon'];
$url = empty( $atts['url'] ) ? '' : $atts['url'];
ob_start();
?>
<div class="social-icon">
<?php if ( ! empty( $url ) ) : ?>
<a href="<?php echo esc_url( $url ); ?>">
<?php endif; ?>
<?php if ( isset( $atts['icon'] ) && nice_bool( $atts['icon'] ) ) : ?>
<i class="fa <?php echo esc_attr( $icon_class ); ?>"></i>
<?php endif; ?>
<?php if ( ! empty( $url ) ) : ?>
</a>
<?php endif; ?>
</div>
<?php
$content = ob_get_contents();
ob_end_clean();
return $content;
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment