Edit File by line
/home/barbar84/www/wp-conte.../themes/twentytw.../inc
File: menu-functions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Functions and filters related to the menus.
[2] Fix | Delete
*
[3] Fix | Delete
* Makes the default WordPress navigation use an HTML structure similar
[4] Fix | Delete
* to the Navigation block.
[5] Fix | Delete
*
[6] Fix | Delete
* @link https://make.wordpress.org/themes/2020/07/06/printing-navigation-block-html-from-a-legacy-menu-in-themes/
[7] Fix | Delete
*
[8] Fix | Delete
* @package WordPress
[9] Fix | Delete
* @subpackage Twenty_Twenty_One
[10] Fix | Delete
* @since Twenty Twenty-One 1.0
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Add a button to top-level menu items that has sub-menus.
[15] Fix | Delete
* An icon is added using CSS depending on the value of aria-expanded.
[16] Fix | Delete
*
[17] Fix | Delete
* @since Twenty Twenty-One 1.0
[18] Fix | Delete
*
[19] Fix | Delete
* @param string $output Nav menu item start element.
[20] Fix | Delete
* @param object $item Nav menu item.
[21] Fix | Delete
* @param int $depth Depth.
[22] Fix | Delete
* @param object $args Nav menu args.
[23] Fix | Delete
*
[24] Fix | Delete
* @return string Nav menu item start element.
[25] Fix | Delete
*/
[26] Fix | Delete
function twenty_twenty_one_add_sub_menu_toggle( $output, $item, $depth, $args ) {
[27] Fix | Delete
if ( 0 === $depth && in_array( 'menu-item-has-children', $item->classes, true ) ) {
[28] Fix | Delete
[29] Fix | Delete
// Add toggle button.
[30] Fix | Delete
$output .= '<button class="sub-menu-toggle" aria-expanded="false" onClick="twentytwentyoneExpandSubMenu(this)">';
[31] Fix | Delete
$output .= '<span class="icon-plus">' . twenty_twenty_one_get_icon_svg( 'ui', 'plus', 18 ) . '</span>';
[32] Fix | Delete
$output .= '<span class="icon-minus">' . twenty_twenty_one_get_icon_svg( 'ui', 'minus', 18 ) . '</span>';
[33] Fix | Delete
$output .= '<span class="screen-reader-text">' . esc_html__( 'Open menu', 'twentytwentyone' ) . '</span>';
[34] Fix | Delete
$output .= '</button>';
[35] Fix | Delete
}
[36] Fix | Delete
return $output;
[37] Fix | Delete
}
[38] Fix | Delete
add_filter( 'walker_nav_menu_start_el', 'twenty_twenty_one_add_sub_menu_toggle', 10, 4 );
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Detects the social network from a URL and returns the SVG code for its icon.
[42] Fix | Delete
*
[43] Fix | Delete
* @since Twenty Twenty-One 1.0
[44] Fix | Delete
*
[45] Fix | Delete
* @param string $uri Social link.
[46] Fix | Delete
* @param int $size The icon size in pixels.
[47] Fix | Delete
*
[48] Fix | Delete
* @return string
[49] Fix | Delete
*/
[50] Fix | Delete
function twenty_twenty_one_get_social_link_svg( $uri, $size = 24 ) {
[51] Fix | Delete
return Twenty_Twenty_One_SVG_Icons::get_social_link_svg( $uri, $size );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Displays SVG icons in the footer navigation.
[56] Fix | Delete
*
[57] Fix | Delete
* @param string $item_output The menu item's starting HTML output.
[58] Fix | Delete
* @param WP_Post $item Menu item data object.
[59] Fix | Delete
* @param int $depth Depth of the menu. Used for padding.
[60] Fix | Delete
* @param stdClass $args An object of wp_nav_menu() arguments.
[61] Fix | Delete
* @return string The menu item output with social icon.
[62] Fix | Delete
*/
[63] Fix | Delete
function twenty_twenty_one_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
[64] Fix | Delete
// Change SVG icon inside social links menu if there is supported URL.
[65] Fix | Delete
if ( 'footer' === $args->theme_location ) {
[66] Fix | Delete
$svg = twenty_twenty_one_get_social_link_svg( $item->url, 24 );
[67] Fix | Delete
if ( ! empty( $svg ) ) {
[68] Fix | Delete
$item_output = str_replace( $args->link_before, $svg, $item_output );
[69] Fix | Delete
}
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
return $item_output;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
add_filter( 'walker_nav_menu_start_el', 'twenty_twenty_one_nav_menu_social_icons', 10, 4 );
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Filters the arguments for a single nav menu item.
[79] Fix | Delete
*
[80] Fix | Delete
* @since Twenty Twenty-One 1.0
[81] Fix | Delete
*
[82] Fix | Delete
* @param stdClass $args An object of wp_nav_menu() arguments.
[83] Fix | Delete
* @param WP_Post $item Menu item data object.
[84] Fix | Delete
* @param int $depth Depth of menu item. Used for padding.
[85] Fix | Delete
*
[86] Fix | Delete
* @return stdClass
[87] Fix | Delete
*/
[88] Fix | Delete
function twenty_twenty_one_add_menu_description_args( $args, $item, $depth ) {
[89] Fix | Delete
$args->link_after = '';
[90] Fix | Delete
if ( 0 === $depth && isset( $item->description ) && $item->description ) {
[91] Fix | Delete
// The extra <span> element is here for styling purposes: Allows the description to not be underlined on hover.
[92] Fix | Delete
$args->link_after = '<p class="menu-item-description"><span>' . $item->description . '</span></p>';
[93] Fix | Delete
}
[94] Fix | Delete
return $args;
[95] Fix | Delete
}
[96] Fix | Delete
add_filter( 'nav_menu_item_args', 'twenty_twenty_one_add_menu_description_args', 10, 3 );
[97] Fix | Delete
[98] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function