Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#49034 new enhancement

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

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


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(
	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 5 months ago.
Adds the filter to the class-twentytwenty-svg-icons.php

Download all attachments as: .zip

Change History (2)

5 months ago

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

Note: See TracTickets for help on using tickets.