• Would you be willing to set the inline icon sprites to use relative paths?

    I have a site on pressable.com and their CDN uses a different domain name – causing CORS issues / not displaying the inline social icons. This is their problem, but maybe a problem others are facing?

Viewing 1 replies (of 1 total)
  • Plugin Contributor Nick C

    (@modernnerd)

    Hi, @amduffy.

    We don’t have plans to switch to relative URLs at the moment, as it could cause issues for CDN users who have CORS correctly configured to allow requests from their domain. (With relative URLs, icons would start loading from their domain instead of from their CDN.)

    If you’re using Simple Social Icons 3.0.0, you can use the new simple_social_icon_html filter to strip the site URL and make the path relative if you wish. Here’s one way to do it:

    add_filter( 'simple_social_icon_html', 'sp_relative_social_icon_urls' );
    /**
     * Use relative paths for Simple Social Icons SVG URLs.
     *
     * May help to avoid security warnings if icons are served from off-site URLs.
     *
     * @param string $html The original icon HTML.
     * @return string The icon HTML with paths made relative instead of absolute.
     */
    function sp_relative_social_icon_urls( $html ) {
    	$site_url = 'https://example.com';
    
    	return str_replace( $site_url, '', $html );
    }

    That code can live at the bottom of your active theme’s functions.php.

    You’d need to replace ‘https://example.com’ with your site URL, or possibly with the path to the CDN URL, depending on how early your CDN plugin adjusts the URL.

    The result will be relative URLs like this:

    Screenshot showing the path of the SVG file with the domain name and protocol stripped.

    You could alternatively ask Pressable to see if they can adjust the CORS policy of their CDN to allow the SVG files to load.

Viewing 1 replies (of 1 total)
  • The topic ‘Relative Path for icon sprite’ is closed to new replies.