WordPress.org

Make WordPress Core

Opened 11 months ago

Closed 6 months ago

Last modified 6 months ago

#49034 closed enhancement (duplicate)

Twenty Twenty: Add filter for social icons regex map to facilitate adding new social icons

Reported by: msaari Owned by:
Milestone: Priority: normal
Severity: minor Version: 5.3
Component: Bundled Theme Keywords: has-patch
Focuses: Cc:

Description

Since adding new social icons is a heavy process, how about making it easier for developers to add their own social icons? It's already possible by overriding the whole TwentyTwenty_SVG_Icons class with your own, but that's a bit much for adding just an icon or two.

On the other hand, overriding the twentytwenty_get_theme_svg() function with your own version that adds couple of more icons is easy. This works really well with UI icons, but less so with social icons. The social icons use regex mapping to automatically match social media service URLs to the correct icons.

To facilitate adding new social media icons, I propose adding a new filter hook in the social link SVG code in the get_social_link_svg() function in classes/class-twentytwenty-svg-icons.php. Applying a filter to the $regex_map variable would allow developers to add new social link regexes to the list and thus add new social link icons easily.

With the new filter, adding a new social icon is simple once you have your own version of twentytwenty_get_theme_svg() that provides the icon SVG. All you need then is this:

add_filter( 'social_icon_regex_map', 'add_telegram' );
function add_telegram( $regex_map ) {
	$telegram_domains = array(
		'telegram.org',
		'telegram.me',
		't.me',
	);
	array_map( 'preg_quote', $telegram_domains );
	$regex_map[ 'telegram' ] = sprintf( '/(%s)/i', implode( '|', $telegram_domains ) );

	return $regex_map;
}

Attachments (1)

class-twentytwenty-svg-icons.php.patch (632 bytes) - added by msaari 11 months ago.
Adds the filter to the class-twentytwenty-svg-icons.php

Download all attachments as: .zip

Change History (4)

@msaari
11 months ago

Adds the filter to the class-twentytwenty-svg-icons.php

#2 @desrosj
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @msaari,

Thanks for taking the time to patch this! I am going to close this out as a duplicate of #48713 because that was created first. It also includes context from some folks that helped develop the theme initially and links to a GitHub pull request where this was actually added (it just seems like it never made its way over).

Please do hop on over there and feel free to add some additional suggestions or details!

#3 @desrosj
6 months ago

  • Version changed from 5.3.1 to 5.3
Note: See TracTickets for help on using tickets.