• Hi Robin,
    Many thanks for making such a small and lightweight sharing plugin.
    I am using facebook and twitter share button on my post only with svg icon.
    When I checked my source code it is injecting html of every icon(SVG). Is there any way to allow SVG html of only those icon which I am going to use?

    Thank you

    • This topic was modified 4 years, 4 months ago by sanjayojha303.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Robin Cornett

    (@littlerchicken)

    The plugin is set up to use SVG icons the same way that the Twenty Nineteen theme does, so it loads the default social network SVG icons as a hidden sprite in the footer. There currently is not a way around that, unless I were to change the plugin at some point to insert the SVG icons using a different method.

    At this time, you could replace the plugin sprite with your own, and disable or modify the plugin SVG using the scriptlesssocialsharing_svg filter. If you are already loading your own SVG sprites, you can disable the plugin sprite with this:

    
    add_filter( 'scriptlesssocialsharing_svg', '__return_false' );
    

    If you create your own sprite file, you can load that instead of the plugin sprite using this code instead:

    
    add_filter( 'scriptlesssocialsharing_svg', 'prefix_scriptless_use_theme_svg' );
    /**
     * Replace the Scriptless Social Sharing sprite file.
     * In this example, the new sprite file is in the active theme, in a subdirectory named svg.
     * The sprite file is named brands.svg.
     * Relative path: /themes/active-theme/svg/brands.svg
     *
     * @return array
     */
    function prefix_scriptless_use_theme_svg() {
    	return array(
    		'styles' => 'brands', // slug(s) for your SVG sprite file
    		'path'   => get_stylesheet_directory() . '/svg', // directory for your SVG sprite file
    	);
    }
    

    (You could copy the sprite file from the plugin and remove the unneeded sprites, and put the new copy in your theme.) Either filter example would go in your theme’s functions.php file or wherever you keep similar code modifications–just please make sure files are backed up and practice safe coding. Hope that helps get you started.

    Thread Starter sanjayojha303

    (@sanjayojha303)

    Wow.. thank you very much for such a great and in depth explanation. I am using child theme so it will be easy for me to do this. Once again thank you very much

    Regards
    Sanjay

    Hi @littlerchicken. I have placed the edited sprite inside /wp-content/brands folder (the brands.svg file). How do I call it properly so it shows the icons? I tried using the url and also content_url()but that didn’t work. I use a parent theme and a custom plugin for PHP functions.

    This solved it, but I had to create a folder named svg inside my plugin. 'path' => plugin_dir_path( __FILE__ ) . 'svg',

    Plugin Author Robin Cornett

    (@littlerchicken)

    If you have svg in your path definition, then it will look for a directory with that name. I did a quick local test for this path:

    
    'path'   => content_url() . '/brands',
    

    and my site did correctly look for brands/brands.svg in the content directory, so you may just want to double check your path parameter, if you want to change this.

    • This reply was modified 4 years, 3 months ago by Robin Cornett. Reason: fix code markup
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Injects HTML of every icons’ is closed to new replies.