';
$svg .= ' ';
$svg .= '';
return $svg;
}
/**
* Add dropdown icon if menu item has children.
*
* @param string $title The menu item's title.
* @param object $item The current menu item.
* @param array $args An array of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
* @return string $title The menu item's title with dropdown icon.
*/
function camer_dropdown_icon_to_menu_link( $title, $item, $args, $depth ) {
if ( 'primary' === $args->theme_location || 'secondary' === $args->theme_location ) {
foreach ( $item->classes as $value ) {
if ( 'menu-item-has-children' === $value || 'page_item_has_children' === $value ) {
$title = $title . '';
}
}
}
return $title;
}
add_filter( 'nav_menu_item_title', 'camer_dropdown_icon_to_menu_link', 10, 4 );
/**
* Return SVG markup for social icons.
*
* @param string $icon SVG icon id.
* @return string $svg SVG markup.
*/
function camer_get_social_svg( $icon = null ) {
// Return early if no icon was defined.
if ( empty( $icon ) ) {
return;
}
// Create SVG markup.
$svg = '';
return $svg;
}
/**
* Display SVG icons in social links menu.
*
* @param string $item_output The menu item output.
* @param WP_Post $item Menu item object.
* @param int $depth Depth of the menu.
* @param array $args wp_nav_menu() arguments.
* @return string $item_output The menu item output with social icon.
*/
function camer_social_icons_menu( $item_output, $item, $depth, $args ) {
// Get supported social icons.
$social_icons = camer_supported_social_icons();
// Change SVG icon inside social links menu if there is supported URL.
if ( 'top-social' === $args->theme_location ) {
$icon = 'star';
foreach ( $social_icons as $attr => $value ) {
if ( false !== strpos( $item_output, $attr ) ) {
$icon = esc_attr( $value );
}
}
$item_output = str_replace( $args->link_after, '' . camer_get_social_svg( $icon ), $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'camer_social_icons_menu', 10, 4 );
/**
* Returns an array of supported social links (URL and icon name).
*
* @return array $social_links_icons
*/
function camer_supported_social_icons() {
// Supported social links icons.
$supported_social_icons = array(
'facebook.com' => 'facebook',
'feed' => 'feed',
'flickr.com' => 'flickr',
'plus.google.com' => 'google-plus',
'instagram.com' => 'instagram',
'linkedin.com' => 'linkedin',
'pinterest.com' => 'pinterest-p',
'twitter.com' => 'twitter',
'vimeo.com' => 'vimeo',
'vk.com' => 'vk',
'youtube.com' => 'youtube',
);
return $supported_social_icons;
}