Troubleshooting & How-Tos 📡 🏷️ 🔍 Programming

Customize Icons for Syndication Links (WP)

The Syndication Links plugin is great for linking out to social media posts related to your WordPress or ClassicPress blog entry. It can also send out those posts to some platforms. But it can’t possibly know every social network out there, or every Mastodon server, and so a lot sites outside the most common will show a generic website icon instead of something more specific.

The plugin has a filter, syn_link_mapping, that you can use to add custom icons for different sites. You can also use it to add icons for different protocols, like if you add Gemini links to the types WordPress will recognize.

For now I’m just adding icons that are already in the set, and mapping them to specific websites or to different protocols. You can see what’s in there by looking in syndication-links/svgs/ and its subfolders.

Here’s how I’m adding them. Note the triple-equals sign for gopher and gemini, because in PHP strpos returns false if not found, and zero if found at the beginning of a string, and double-equals would match zero to both of those.

function exampleprefix_map_syndication_icons( $icon, $url ) {
	if (strpos($url, '//wandering.shop/') > 0 || strpos($url, 'photog.social') > 0 )
		return 'mastodon';
	if (strpos($url, 'inaturalist.org/') > 0)
		return 'bug';
	if (strpos($url, 'gopher://') === 0 )
		return 'hierarchy';
	if (strpos($url, 'gemini://') === 0 )
		return 'standard';
	return $icon;
}
add_filter('syn_link_mapping', 'exampleprefix_map_syndication_icons', 20, 2);

These can go in a functions.php file in your theme, or in a custom functionality plugin. As always, be sure to set your own prefix on these functions so they don’t collide with another plugin’s function names.

TODO: I’d like to pick out (or maybe draw) some more specific icons for Gopher and Gemini. Going by the README, it’s going to involve pre_syn_link_icon and maybe plugging some raw SVG into it? When I do, I’ll update this page.