Customizing Social Profile Links for Individual Authors in Single Posts
|
/ Documentation /Custom Code Snippets/Blog Filters/ Customizing Social Profile Links for Individual Authors in Single Posts

Customizing Social Profile Links for Individual Authors in Single Posts

Astra’s customizer option (Customizer > Blog > Single Post > Author Info) allows setting a single social URL for authors. While this works well for single author websites, it presents a challenge in multi-author scenarios, as the set URL applies to all authors, regardless of who wrote the content.

To address this limitation and enable individualized author profiles, a specific code snippet can be implemented. This document provides detailed instructions on using the snippet to assign unique social links to each author.

Customize Social Profile Links for Individual Authors in Single Posts

Using the below-attached simple code snippet, you can unlock author-specific social links, allowing you to showcase each writer’s unique social profile links alongside their work.

You can add the below provided code to your child theme’s functions.php file

add_filter( 'astra_addon_author_social_sharing_link', 'update_author_wise_social_links', 10, 2 );

function update_author_wise_social_links( $social_link, $network ) {

	global $post;
	$post_author_id = ! empty( $post->post_author ) ? absint( $post->post_author ) : 1;

	switch ( $network ) {
		case 'facebook':
			if ( 43 === $post_author_id ) {
				$social_link = 'https://www.facebook.com/astra-team'; // For author user id 43
			} elseif ( 4 === $post_author_id ) {
				$social_link = 'https://www.facebook.com/admin'; // For author user id 4
			} else {
				$social_link = 'https://www.facebook.com/brainstormforce'; // Fallback facebook social link
			}
			break;

		case 'twitter':
			$social_link = 'https://twitter.com/bsfwp';
			break;

		case 'linkedin':
			$social_link = 'https://www.linkedin.com/company/brainstorm-force/';
			break;

		case 'youtube':
			$social_link = 'https://www.youtube.com/channel/UCP6LzCTEr7ZKTuWzc9ZxVqw';
			break;

		default:
			// Do nothing or extend this case as per other social networks.
			break;
	}

	return $social_link;
}

You can update the example social links with the actual URLs of your authors and adjust the author IDs to match your specific users.

In this example, the snippet differentiates Facebook links based on the author, providing unique Social links for each author, thus overcoming the issue of uniform Social links for multiple authors.

We hope this document has been helpful. If you have any queries further, feel free to leave a comment below.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
On this page

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form