Edit File by line
/home/barbar84/public_h.../wp-conte.../themes/twentyni.../inc
File: icon-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* SVG icons related functions
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Twenty_Nineteen
[5] Fix | Delete
* @since Twenty Nineteen 1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Gets the SVG code for a given icon.
[10] Fix | Delete
*/
[11] Fix | Delete
function twentynineteen_get_icon_svg( $icon, $size = 24 ) {
[12] Fix | Delete
return TwentyNineteen_SVG_Icons::get_svg( 'ui', $icon, $size );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Gets the SVG code for a given social icon.
[17] Fix | Delete
*/
[18] Fix | Delete
function twentynineteen_get_social_icon_svg( $icon, $size = 24 ) {
[19] Fix | Delete
return TwentyNineteen_SVG_Icons::get_svg( 'social', $icon, $size );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Detects the social network from a URL and returns the SVG code for its icon.
[24] Fix | Delete
*/
[25] Fix | Delete
function twentynineteen_get_social_link_svg( $uri, $size = 24 ) {
[26] Fix | Delete
return TwentyNineteen_SVG_Icons::get_social_link_svg( $uri, $size );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Display SVG icons in social links menu.
[31] Fix | Delete
*
[32] Fix | Delete
* @param string $item_output The menu item's starting HTML output.
[33] Fix | Delete
* @param WP_Post $item Menu item data object.
[34] Fix | Delete
* @param int $depth Depth of the menu. Used for padding.
[35] Fix | Delete
* @param stdClass $args An object of wp_nav_menu() arguments.
[36] Fix | Delete
* @return string The menu item output with social icon.
[37] Fix | Delete
*/
[38] Fix | Delete
function twentynineteen_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
[39] Fix | Delete
// Change SVG icon inside social links menu if there is supported URL.
[40] Fix | Delete
if ( 'social' === $args->theme_location ) {
[41] Fix | Delete
$svg = twentynineteen_get_social_link_svg( $item->url, 26 );
[42] Fix | Delete
if ( empty( $svg ) ) {
[43] Fix | Delete
$svg = twentynineteen_get_icon_svg( 'link' );
[44] Fix | Delete
}
[45] Fix | Delete
$item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
return $item_output;
[49] Fix | Delete
}
[50] Fix | Delete
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_nav_menu_social_icons', 10, 4 );
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Add a dropdown icon to top-level menu items.
[54] Fix | Delete
*
[55] Fix | Delete
* @param string $item_output The menu item's starting HTML output.
[56] Fix | Delete
* @param WP_Post $item Menu item data object.
[57] Fix | Delete
* @param int $depth Depth of the menu. Used for padding.
[58] Fix | Delete
* @param stdClass $args An object of wp_nav_menu() arguments.
[59] Fix | Delete
* @return string Nav menu item start element.
[60] Fix | Delete
*/
[61] Fix | Delete
function twentynineteen_add_dropdown_icons( $item_output, $item, $depth, $args ) {
[62] Fix | Delete
[63] Fix | Delete
// Only add class to 'top level' items on the 'primary' menu.
[64] Fix | Delete
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
[65] Fix | Delete
return $item_output;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
if ( in_array( 'mobile-parent-nav-menu-item', $item->classes, true ) && isset( $item->original_id ) ) {
[69] Fix | Delete
// Inject the keyboard_arrow_left SVG inside the parent nav menu item, and let the item link to the parent item.
[70] Fix | Delete
// @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
[71] Fix | Delete
$link = sprintf(
[72] Fix | Delete
'<button class="menu-item-link-return" tabindex="-1">%s',
[73] Fix | Delete
twentynineteen_get_icon_svg( 'chevron_left', 24 )
[74] Fix | Delete
);
[75] Fix | Delete
[76] Fix | Delete
// Replace opening <a> with <button>.
[77] Fix | Delete
$item_output = preg_replace(
[78] Fix | Delete
'/<a\s.*?>/',
[79] Fix | Delete
$link,
[80] Fix | Delete
$item_output,
[81] Fix | Delete
1 // Limit.
[82] Fix | Delete
);
[83] Fix | Delete
[84] Fix | Delete
// Replace closing </a> with </button>.
[85] Fix | Delete
$item_output = preg_replace(
[86] Fix | Delete
'#</a>#i',
[87] Fix | Delete
'</button>',
[88] Fix | Delete
$item_output,
[89] Fix | Delete
1 // Limit.
[90] Fix | Delete
);
[91] Fix | Delete
[92] Fix | Delete
} elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
[93] Fix | Delete
[94] Fix | Delete
// Add SVG icon to parent items.
[95] Fix | Delete
$icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
[96] Fix | Delete
[97] Fix | Delete
$item_output .= sprintf(
[98] Fix | Delete
'<button class="submenu-expand" tabindex="-1">%s</button>',
[99] Fix | Delete
$icon
[100] Fix | Delete
);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
return $item_output;
[104] Fix | Delete
}
[105] Fix | Delete
add_filter( 'walker_nav_menu_start_el', 'twentynineteen_add_dropdown_icons', 10, 4 );
[106] Fix | Delete
[107] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function