我正在尝试将图标添加到二十一个社交图标中,但注册时遇到了问题。
This support article 指的是Themes field guide for WordPress 5.5 它提供了有关如何添加自定义图标并将其挂钩的说明,以便在键入相关url作为菜单项自定义链接时显示该图标。
我复制了Field Guide中的函数,将挂钩更改为与2021主题相匹配,而不是与2020年主题相匹配(因为twentytwentyone/classes/class-twenty-twenty-one-svg-icons.php
是twenty_twenty_one_svg_icons_social
).
下面是我添加到函数中的函数。php:(抱歉——包括完整的svg向量,以防它们导致错误)
function mychildtheme_twenty_twenty_one_social_icons_map( $icons ) {
$icons[\'rhs-calendar\'] = array(
\'rhs-1.test\',
\'rhs-1.test/events/list/\',
);
return $icons;
}
add_filter( \'twenty_twenty_one_social_icons_map\', \'mychildtheme_twenty_twenty_one_social_icons_map\' );
// add the calendar icon
function mychildtheme_twenty_twenty_one_svg_icons_social( $icons ) {
$icons[\'rhs-calendar\'] = \'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<path fill-rule="evenodd" d="M 6.75,0 C 7.1642136,0 7.5,0.33578644 7.5,0.75 V 3 h 9 V 0.75 c 0,-0.99999957 1.5,-0.99999957 1.5,0 V 3 h 2.75 c 0.966,0 1.75,0.784 1.75,1.75 v 16 c 0,0.966498 -0.783502,1.75 -1.75,1.75 H 3.25 C 2.2835017,22.5 1.5,21.716498 1.5,20.75 v -16 C 1.5,3.784 2.284,3 3.25,3 H 6 V 0.75 C 6,0.33578644 6.3357864,0 6.75,0 Z M 21,7.9375 H 3 V 20.75 C 3,20.888 3.112,21 3.25,21 h 17.5 C 20.888071,21 21,20.888071 21,20.75 Z" id="path833"/>
<path d="m 7.2944571,17.386715 h 4.1851359 v 1.803463 H 4.9127844 v -0.743412 q 0,-0.75718 0.2546876,-1.356039 0.2546875,-0.605744 0.6401605,-1.080702 0.3854731,-0.481841 0.8397806,-0.846664 0.4611909,-0.371706 0.8741978,-0.667694 0.4336571,-0.309755 0.7571791,-0.591976 0.3304055,-0.282222 0.5506758,-0.55756 0.2271538,-0.282221 0.3372889,-0.564442 0.1101352,-0.289105 0.1101352,-0.612627 0,-0.633277 -0.3579393,-0.956799 -0.3579392,-0.323522 -1.0944681,-0.323522 -1.2734377,0 -2.4367402,1.011866 V 9.9870092 q 1.2872046,-0.8328971 2.9048146,-0.8328971 0.7502958,0 1.3422722,0.19962 0.5988599,0.1927365 1.0118669,0.5575592 0.413007,0.3648227 0.626394,0.8879647 0.22027,0.516258 0.22027,1.156419 0,0.681461 -0.213387,1.211487 -0.206503,0.530025 -0.557559,0.963682 -0.344173,0.433657 -0.7984801,0.79848 Q 9.4696264,15.287263 8.9809016,15.624552 8.6504962,15.85859 8.3407411,16.092627 8.0378694,16.31978 7.8038322,16.546934 7.569795,16.767205 7.432126,16.980591 7.2944571,17.193978 7.2944571,17.386715 Z" />
<path d="m 12.97644,18.93549 v -1.85853 q 1.011866,0.61951 2.154518,0.61951 0.860431,0 1.342273,-0.406123 0.488724,-0.413007 0.488724,-1.115119 0,-1.466174 -2.071917,-1.466174 -0.764063,0 -1.762163,0.117018 l 0.371707,-5.5067572 h 5.224536 v 1.7759292 h -3.565626 l -0.137669,1.975549 q 0.530026,-0.0413 0.915499,-0.0413 1.521242,0 2.381672,0.79848 0.860431,0.79848 0.860431,2.147635 0,1.493708 -1.025633,2.443624 -1.025634,0.943032 -2.780913,0.943032 -1.424873,0 -2.395439,-0.426774 z"/>
</svg>\';
return $icons;
}
add_filter( \'twenty_twenty_one_svg_icons_social\', \'mychildtheme_twenty_twenty_one_svg_icons_social\' );
新函数和筛选器引发以下错误:
Warning: preg_match(): Unknown modifier \'v\' in C:\\laragon\\www\\rhs-1\\wp-content\\themes\\twentytwentyone\\
classes\\class-twenty-twenty-one-svg-icons.php on line 243
相关线路输入
class-twenty-twenty-one-svg-icons.php
:
242 foreach ( $regex_map as $icon => $regex ) {
243 if ( preg_match( $regex, $uri ) ) {
244 return self::get_svg( \'social\', $icon, $size ) . \'<span class="screen-reader-text">\';
245 }
246 }
现在,中的说明
this answer 将图标包括在;icons\\u map“图标”;功能完全不同,我应该这样做吗?
其次,根据这个答案,我不知道我是否以及为什么必须解开家长主题社交图标?
第三,如果我还想在古腾堡使用这个图标,我是不是运气太好了;“社交图标”;block,或者是否有其他方式将社交图标(二级)菜单包含为Gutenberg block?