• Resolved Giuseppe

    (@mociofiletto)


    Hi, I am trying to expand class TwentyTwenty_SVG_Icons to add new social icons in a child theme. I have seen the solution posted here: https://www.ads-software.com/support/topic/icon-whatsapp-in-social-menu-2/#post-12284873 but this is not the way I’d like to do.
    Now I have created a new files in child_theme/classes/ named “more-svg-icons.php”
    and this is the content:

    
    <?php
    function extend_array ($arr_parent, $arr_added) {
    	foreach ($arr_added as $key => $value) {
    		$arr_parent[$key] = $value;
    	}
    }
    
    $more_ui_icons = array();
    $more_social_icons_map = array();
    $more_social_icons = array(
    		'wikiloc' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="https://www.w3.org/2000/svg"><path d="M 10.432223,23.937116 C 9.2238297,23.781697 7.8596607,23.382624 6.732963,22.854936 6.1610221,22.587068 6.0147372,22.48416 5.6685893,22.106182 4.5859757,20.924017 3.8615842,19.498335 3.5049074,17.847819 3.3169046,16.977838 3.3017322,15.285727 3.4741787,14.420789 3.7297124,13.139139 4.3297278,11.777522 5.0889694,10.756353 5.6164518,10.046901 6.5697926,9.0505798 7.2310225,8.5177327 8.2209774,7.7199846 8.8194019,7.4172273 11.278133,6.470202 13.308866,5.6880296 14.8614,4.1528171 15.281067,2.5119343 c 0.140448,-0.5491441 0.168556,-1.4812138 0.05899,-1.95642639 -0.03591,-0.15575944 -0.05393,-0.29454345 -0.04006,-0.30844112 0.03737,-0.0375093 1.075589,0.3382078 1.617247,0.58504718 0.442291,0.20153973 0.479772,0.23510553 0.615956,0.55169763 0.43878,1.0199712 0.581277,2.5497734 0.344238,3.6956412 -0.397424,1.9211965 -1.60189,3.5209633 -3.664556,4.8672597 -0.779031,0.5084705 -1.109394,0.7741035 -1.682226,1.3526105 -1.363198,1.376707 -2.197355,2.947549 -2.528526,4.761605 -0.1634883,0.895537 -0.1478439,2.410109 0.03379,3.27332 0.337246,1.602542 1.100082,3.134451 2.085319,4.187671 0.208449,0.222835 0.378996,0.423258 0.378996,0.445388 0,0.05722 -1.566231,0.03438 -2.068068,-0.0302 z m 2.546611,-0.786389 c -1.484563,-1.556121 -2.223474,-3.397616 -2.223474,-5.541279 0,-2.166089 0.807722,-4.091558 2.387982,-5.692532 0.463951,-0.470019 0.857274,-0.783653 1.584222,-1.263213 2.649414,-1.747784 3.993479,-3.856286 4.145484,-6.5032277 0.02626,-0.4574201 0.0061,-0.8701702 -0.06518,-1.335337 -0.05676,-0.3702829 -0.09006,-0.6864181 -0.07401,-0.7024797 0.06586,-0.065882 1.148615,0.8581865 1.812517,1.5468406 0.897139,0.9305884 1.465273,1.7264374 2.02316,2.8340789 0.841288,1.6703178 1.229445,3.190238 1.28734,5.0409179 0.06631,2.120188 -0.293246,3.853518 -1.173019,5.654875 -1.129147,2.311908 -2.917919,4.139124 -5.213096,5.325138 -1.172591,0.605926 -2.496454,1.044343 -3.619457,1.198635 l -0.296985,0.04083 z M 2.8939936,19.709192 c -1.422649,-1.64777 -2.34038106,-3.599316 -2.75013147,-5.848117 -0.19181617,-1.052729 -0.19181617,-2.88953 0,-3.9422589 C 0.5929001,7.4543998 1.6173689,5.4157272 3.2852617,3.6674863 5.0383785,1.8299211 7.1804965,0.65932662 9.7213251,0.15039423 10.356947,0.02305531 10.665683,0.00131921 11.854021,2.0828208e-5 12.744462,-9.313573e-4 13.437532,0.03079774 13.783736,0.08831169 c 0.528973,0.08790605 0.542306,0.09463861 0.639733,0.32315609 0.05734,0.13445603 0.112036,0.50722522 0.129078,0.87962412 0.0521,1.1382453 -0.241082,1.8779746 -1.106749,2.7924921 -0.679873,0.718238 -1.416913,1.2020057 -2.43193,1.5962273 C 9.192122,6.3873644 8.7878602,6.5604599 8.2116763,6.8796534 7.3675618,7.347268 6.5721878,7.9592162 5.7757351,8.7537953 4.2197217,10.306152 3.3347773,11.746562 2.8466522,13.521415 c -0.280059,1.018322 -0.3313263,1.423083 -0.3295134,2.601608 0.00204,1.328867 0.1035689,1.981491 0.4865967,3.127996 0.1413184,0.423008 0.2450806,0.780968 0.2305842,0.795465 -0.014457,0.01446 -0.1676466,-0.137282 -0.3403261,-0.337292 z"></path></svg>'
    );
    
    extend_array(TwentyTwenty_SVG_Icons::$ui_icons, $more_ui_icons);
    extend_array(TwentyTwenty_SVG_Icons::$social_icons_map, $more_social_icons_map);
    extend_array(TwentyTwenty_SVG_Icons::$social_icons, $more_social_icons);
    

    Now I’m trying to call it using an hook in child_theme/functions.php and this is what i have written there:

    
    function mytheme_includes() {
    	require_once get_theme_file_path( 'classes/more-svg-icons.php' );
    }
    add_action( 'after_setup_theme', 'mytheme_includes' );
    

    I am not sure if I’m going the right way, I have tried different hooks like ‘widgets_init’, but the result is always the same: it doesn’t work.

    Thanks for help

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Giuseppe

    (@mociofiletto)

    Solved:

    
    <?php
    function extend_array ($arr_parent, $arr_added) {
    	foreach ($arr_added as $key => $value) {
    		$arr_parent[$key] = $value;
    	}
    	return ($arr_parent);
    }
    
    $more_ui_icons = array();
    $more_social_icons_map = array();
    $more_social_icons = array(
    		'wikiloc' => '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="https://www.w3.org/2000/svg"><path d="M 10.432223,23.937116 C 9.2238297,23.781697 7.8596607,23.382624 6.732963,22.854936 6.1610221,22.587068 6.0147372,22.48416 5.6685893,22.106182 4.5859757,20.924017 3.8615842,19.498335 3.5049074,17.847819 3.3169046,16.977838 3.3017322,15.285727 3.4741787,14.420789 3.7297124,13.139139 4.3297278,11.777522 5.0889694,10.756353 5.6164518,10.046901 6.5697926,9.0505798 7.2310225,8.5177327 8.2209774,7.7199846 8.8194019,7.4172273 11.278133,6.470202 13.308866,5.6880296 14.8614,4.1528171 15.281067,2.5119343 c 0.140448,-0.5491441 0.168556,-1.4812138 0.05899,-1.95642639 -0.03591,-0.15575944 -0.05393,-0.29454345 -0.04006,-0.30844112 0.03737,-0.0375093 1.075589,0.3382078 1.617247,0.58504718 0.442291,0.20153973 0.479772,0.23510553 0.615956,0.55169763 0.43878,1.0199712 0.581277,2.5497734 0.344238,3.6956412 -0.397424,1.9211965 -1.60189,3.5209633 -3.664556,4.8672597 -0.779031,0.5084705 -1.109394,0.7741035 -1.682226,1.3526105 -1.363198,1.376707 -2.197355,2.947549 -2.528526,4.761605 -0.1634883,0.895537 -0.1478439,2.410109 0.03379,3.27332 0.337246,1.602542 1.100082,3.134451 2.085319,4.187671 0.208449,0.222835 0.378996,0.423258 0.378996,0.445388 0,0.05722 -1.566231,0.03438 -2.068068,-0.0302 z m 2.546611,-0.786389 c -1.484563,-1.556121 -2.223474,-3.397616 -2.223474,-5.541279 0,-2.166089 0.807722,-4.091558 2.387982,-5.692532 0.463951,-0.470019 0.857274,-0.783653 1.584222,-1.263213 2.649414,-1.747784 3.993479,-3.856286 4.145484,-6.5032277 0.02626,-0.4574201 0.0061,-0.8701702 -0.06518,-1.335337 -0.05676,-0.3702829 -0.09006,-0.6864181 -0.07401,-0.7024797 0.06586,-0.065882 1.148615,0.8581865 1.812517,1.5468406 0.897139,0.9305884 1.465273,1.7264374 2.02316,2.8340789 0.841288,1.6703178 1.229445,3.190238 1.28734,5.0409179 0.06631,2.120188 -0.293246,3.853518 -1.173019,5.654875 -1.129147,2.311908 -2.917919,4.139124 -5.213096,5.325138 -1.172591,0.605926 -2.496454,1.044343 -3.619457,1.198635 l -0.296985,0.04083 z M 2.8939936,19.709192 c -1.422649,-1.64777 -2.34038106,-3.599316 -2.75013147,-5.848117 -0.19181617,-1.052729 -0.19181617,-2.88953 0,-3.9422589 C 0.5929001,7.4543998 1.6173689,5.4157272 3.2852617,3.6674863 5.0383785,1.8299211 7.1804965,0.65932662 9.7213251,0.15039423 10.356947,0.02305531 10.665683,0.00131921 11.854021,2.0828208e-5 12.744462,-9.313573e-4 13.437532,0.03079774 13.783736,0.08831169 c 0.528973,0.08790605 0.542306,0.09463861 0.639733,0.32315609 0.05734,0.13445603 0.112036,0.50722522 0.129078,0.87962412 0.0521,1.1382453 -0.241082,1.8779746 -1.106749,2.7924921 -0.679873,0.718238 -1.416913,1.2020057 -2.43193,1.5962273 C 9.192122,6.3873644 8.7878602,6.5604599 8.2116763,6.8796534 7.3675618,7.347268 6.5721878,7.9592162 5.7757351,8.7537953 4.2197217,10.306152 3.3347773,11.746562 2.8466522,13.521415 c -0.280059,1.018322 -0.3313263,1.423083 -0.3295134,2.601608 0.00204,1.328867 0.1035689,1.981491 0.4865967,3.127996 0.1413184,0.423008 0.2450806,0.780968 0.2305842,0.795465 -0.014457,0.01446 -0.1676466,-0.137282 -0.3403261,-0.337292 z"></path></svg>'
    );
    
    TwentyTwenty_SVG_Icons::$ui_icons = extend_array(TwentyTwenty_SVG_Icons::$ui_icons, $more_ui_icons);
    TwentyTwenty_SVG_Icons::$social_icons_map= extend_array(TwentyTwenty_SVG_Icons::$social_icons_map, $more_social_icons_map);
    TwentyTwenty_SVG_Icons::$social_icons = extend_array(TwentyTwenty_SVG_Icons::$social_icons, $more_social_icons);
    
    

    Interested in this approach, but I keep getting a critical wp error as soon as I assign

    TwentyTwenty_SVG_Icons::$ui_icons = extend_array(TwentyTwenty_SVG_Icons::$ui_icons, $more_ui_icons);
    TwentyTwenty_SVG_Icons::$social_icons_map= extend_array(TwentyTwenty_SVG_Icons::$social_icons_map, $more_social_icons_map);
    TwentyTwenty_SVG_Icons::$social_icons = extend_array(TwentyTwenty_SVG_Icons::$social_icons, $more_social_icons);
    

    Any help appreciated, thanks.

    Prob solved, unrelated inclusion error. Thx.

    @mociofiletto Just to let you know: THANKYOU!

    This solved a similiar problem I had.

    Greetings from Cologne/Germany,

    mo.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding new social icons’ is closed to new replies.