Last active
February 3, 2022 09:53
-
-
Save tiborp/9711443 to your computer and use it in GitHub Desktop.
Add span tag around WordPress menu item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add span to menu items with icon class so we can hide the text and show icons instead | |
* | |
* @link http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items | |
*/ | |
add_filter( 'walker_nav_menu_start_el', 'hrt_span_to_nav_menu', 10, 4 ); | |
function hrt_span_to_nav_menu( $item_output, $item, $depth, $args ) { | |
if ( isset( $item->classes ) && !empty( $item->classes ) ) { | |
if ( in_array( 'icon-twitter', (array) $item->classes ) || in_array( 'icon-linkedin', (array) $item->classes ) ) { | |
$item_output = '<span><a href="'. $item->url .'" title="'. $item->attr_title .'"></a></span>'; | |
} | |
} | |
return $item_output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment