The Social Links module lets users choose profile links for their theme’s social media integration from selected services connected to Publicize. To use this you will need to:
- Add theme support through the
add_theme_support()function in your theme.
- Use the Theme Modifications API to pull the data in to your theme template.
Enabling Social Links is very similar to adding support for post thumbnails or editor styles because we make use of
add_theme_support(). By providing an array with slugs of the supported services as the second argument when calling
add_theme_support(), Social Links will pass on just the information your theme needs. Social Links currently supports only four services: Facebook, Twitter, LinkedIn, and Tumblr. Since every theme is different and certain themes might not support all services, themes need to specify services:
add_theme_support( 'social-links', array( 'facebook', 'twitter', 'linkedin', 'tumblr' ) );
Using the information
Social Links makes the information available through the Theme Modifications API. This way themes can pull that information with a call to
get_theme_mod() and work with it. As a theme developer you always want to check if the user has actually set a link for that service before using it. You can rely on core’s default value of
false, or pass an empty string as a second argument when you want to deal with consistent data types. We prefixed the theme modification name with
'jetpack', to not collide with any other plugin or theme functionality that might use just the service name. This is how an implementation in a template file could look, after a check if the URL was set:
<a href="<?php echo esc_url( get_theme_mod( 'jetpack-facebook' ) ); ?>"> <?php _e( 'Facebook', 'textdomain' ); ?> </a>
Please note that while the data is available via
get_theme_mod(), it’s actually stored as a serialized value in the Jetpack Options — not as a theme mod. We’re just using some filters behind the scenes to make it more easily accessible to developers with
get_theme_mod(), so you don’t need to use custom functions that could break if your users don’t have Jetpack installed!