Created
September 10, 2012 15:45
-
-
Save leoj3n/3691661 to your computer and use it in GitHub Desktop.
replace "Home" link in primary nav with an icon
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
// replace "Home" link in primary nav with an icon | |
add_filter( 'walker_nav_menu_start_el', 'pp_walker_nav_menu_start_el', 11, 4 ); | |
function pp_walker_nav_menu_start_el( $item_output, $item, $depth, $args ) { | |
if (($args->theme_location == 'primary_navigation') && ($item->title == 'Home')) { | |
$domDocument = new DOMDocument(); | |
$domDocument->loadHTML($item_output); | |
$domElement = $domDocument->createElement('i', ''); | |
$domElement->setAttribute('class', 'icon-home icon-large'); | |
$item = $domDocument->getElementsByTagName('a')->item(0); | |
$item->nodeValue = ''; | |
$item->appendChild($domElement); | |
$item_output = $domDocument->saveHTML(); // <a href="/"><i class="icon-home icon-large"></i></a> | |
} | |
return $item_output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment