Skip to content

Instantly share code, notes, and snippets.

@leoj3n
Created September 10, 2012 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoj3n/3691661 to your computer and use it in GitHub Desktop.
Save leoj3n/3691661 to your computer and use it in GitHub Desktop.
replace "Home" link in primary nav with an icon
// 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