Skip to content

Instantly share code, notes, and snippets.

@samikeijonen
Last active September 11, 2016 09:20
Show Gist options
  • Select an option

  • Save samikeijonen/f9726b4e75e79f8acf4a4e8d5104cb8a to your computer and use it in GitHub Desktop.

Select an option

Save samikeijonen/f9726b4e75e79f8acf4a4e8d5104cb8a to your computer and use it in GitHub Desktop.
Icons to navigation
<?php
/**
* Add SVG icon for dropdown in primary navigation.
*
* @since 1.0.0
*
* @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 Menu item with SVG icon.
*/
function checathlon_dropdown_icon_to_menu_links( $item_output, $item, $depth, $args ) {
if ( 'primary' == $args->theme_location ) {
foreach ( $item->classes as $value ) {
if ( $value == 'menu-item-has-children' ) {
//$item_output = $item_output . checathlon_get_svg( array( 'icon' => 'expand' ) );
//$item_output = str_replace( $args->link_after, '</span>' . checathlon_get_svg( array( 'icon' => 'expand' ) ), $item_output );
$item_output = str_replace( '</a>', checathlon_get_svg( array( 'icon' => 'expand' ) ) . '</a>', $item_output );
}
}
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'checathlon_dropdown_icon_to_menu_links', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment