• Resolved Anonymous User 17976131

    (@anonymized-17976131)


    So, I was trying to see whether or not I could use this solution in another theme’s support forum to add a “site” icon to Seedlet’s social icons stuff, via a custom function using the Code Snippets plugin.

    I gather there’s not an exact 1:1 correlation here in approaches (child theme function.php vs. Code Snippets), but I’m stuck on figuring out if there’s a way to make this work.

    I’ve been using add_action('after_setup_theme', 'extend_icons_array'); to avoid an error where the Seedlet_SVG_Icons isn’t found, but then even if I require that class file in the function, it then errors out saying the class is already in use and can’t be declared.

    What am I (possibly very obviously to actual coders) missing here?

    Thanks. For reference, below is the current version that’s barfing.

    function extend_icons_array ($arr_parent, $arr_added) {
    	require(get_template_directory( __FILE__ ).'/classes/class-seedlet-svg-icons.php');
    	foreach ($arr_added as $key => $value) {
    		$arr_parent[$key] = $value;
    	}
    	return ($arr_parent);
    }
    
    $more_ui_icons = array();
    $more_social_icons_map = array(
    	'site'	=> array(
    		'slow.dog',
    	),
    );
    $more_social_icons = array(
    	'site'	=> '<svg viewBox="0 0 24 24" version="1.1" xmlns="https://www.w3.org/2000/svg"><path fill="currentColor" d="M9 0a9 9 0 1 0 0 18A9 9 0 0 0 9 0Zm3.46 11.95c0 1.47-.8 3.3-4.06 4.7c.3-4.17-2.52-3.69-3.2-5A3.25 3.25 0 0 1 7 9.1a8.49 8.49 0 0 1-4.18-2c.05.47.279.904.64 1.21a4.18 4.18 0 0 1-1.94-1.5a7.94 7.94 0 0 1 7.25-5.63c-.84 1.38-1.5 4.13 0 5.57C7.23 7 6.26 5 5.41 5.79c-1.13 1.06.33 2.51 3.42 3.08c3.29.59 3.66 1.58 3.63 3.08Zm1.34-4c-.32-1.11.62-2.23 1.69-3.14a7.27 7.27 0 0 1 .84 6.68c-.77-1.89-2.17-2.32-2.53-3.57v.03Z"/></svg>'
    );
    
    Seedlet_SVG_Icons::$ui_icons = extend_icons_array(Seedlet_SVG_Icons::$ui_icons, $more_ui_icons);
    Seedlet_SVG_Icons::$social_icons_map= extend_icons_array(Seedlet_SVG_Icons::$social_icons_map, $more_social_icons_map);
    Seedlet_SVG_Icons::$social_icons = extend_icons_array(Seedlet_SVG_Icons::$social_icons, $more_social_icons);
    
    add_action('after_setup_theme', 'extend_icons_array');
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi there!

    I’m afraid we’re not able to provide support for advanced customization like this to our themes. I will, however, leave this thread open in case someone from the community has a solution for you ??
    You can also consider asking for help in the advanced forum, or somewhere like wordpress.stackexchange.com.

    I hope that helps!

    Thread Starter Anonymous User 17976131

    (@anonymized-17976131)

    FWIW, I was able to find and use code from here to make the following work to add a completely new item to $social_icons and $social_icons_map. So I’ll just mark this as resolved.

    function extend_array() {
    	Seedlet_SVG_Icons::$social_icons_map['site'] = 'slow.dog';
        Seedlet_SVG_Icons::$social_icons['site'] = '<svg viewBox="0 0 20 20" version="1.1" xmlns="https://www.w3.org/2000/svg"><path d="M9 0a9 9 0 1 0 0 18A9 9 0 0 0 9 0Zm3.46 11.95c0 1.47-.8 3.3-4.06 4.7c.3-4.17-2.52-3.69-3.2-5A3.25 3.25 0 0 1 7 9.1a8.49 8.49 0 0 1-4.18-2c.05.47.279.904.64 1.21a4.18 4.18 0 0 1-1.94-1.5a7.94 7.94 0 0 1 7.25-5.63c-.84 1.38-1.5 4.13 0 5.57C7.23 7 6.26 5 5.41 5.79c-1.13 1.06.33 2.51 3.42 3.08c3.29.59 3.66 1.58 3.63 3.08Zm1.34-4c-.32-1.11.62-2.23 1.69-3.14a7.27 7.27 0 0 1 .84 6.68c-.77-1.89-2.17-2.32-2.53-3.57v.03Z"></path></svg>';
    }
    add_action('after_setup_theme', 'extend_array');

    Thanks for sharing the solution here. Hopefully someone else can also benefit from it ??

    Thread Starter Anonymous User 17976131

    (@anonymized-17976131)

    Just a proviso for anyone who might want to use this: it apparently doesn’t work if you try to add more than one new icon. For some reason it just uses the first custom icon for each additional extra item you you try to add to the menu.

    Thanks for that update, too! While we can’t offer any custom development here, if you’d like to share the code as you have it (with the extra icons) someone might be able to spot the issue.

    Thread Starter Anonymous User 17976131

    (@anonymized-17976131)

    It’s possible that the problem is my not actually understanding code. I just try to grasp the general logic and try things I see out there. But if I take my above code and try to add things…

    function extend_array() {
    	Seedlet_SVG_Icons::$social_icons_map['site'] = 'slow.dog';
    	Seedlet_SVG_Icons::$social_icons['site'] = '<svg viewBox="0 0 20 20" version="1.1" xmlns="https://www.w3.org/2000/svg"><path d="M9 0a9 9 0 1 0 0 18A9 9 0 0 0 9 0Zm3.46 11.95c0 1.47-.8 3.3-4.06 4.7c.3-4.17-2.52-3.69-3.2-5A3.25 3.25 0 0 1 7 9.1a8.49 8.49 0 0 1-4.18-2c.05.47.279.904.64 1.21a4.18 4.18 0 0 1-1.94-1.5a7.94 7.94 0 0 1 7.25-5.63c-.84 1.38-1.5 4.13 0 5.57C7.23 7 6.26 5 5.41 5.79c-1.13 1.06.33 2.51 3.42 3.08c3.29.59 3.66 1.58 3.63 3.08Zm1.34-4c-.32-1.11.62-2.23 1.69-3.14a7.27 7.27 0 0 1 .84 6.68c-.77-1.89-2.17-2.32-2.53-3.57v.03Z"></path></svg>';
    	Seedlet_SVG_Icons::$social_icons_map['othersite'] = 'other.domain';
    	Seedlet_SVG_Icons::$social_icons['othersite'] = 'some svg code';}
    add_action('after_setup_theme', 'extend_array');

    …both spots in the menu use that first of the two icons—rather than the link to the first custom domain/icon using its icon above, and the link to the second custom domain/icon using its icon above.

    I guess I just sort of assumed in my code ignorance that adding a second set of code in the same form as the first set of code would work, but it doesn’t.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding a social icon via custom function?’ is closed to new replies.