Skip to content

Instantly share code, notes, and snippets.

@trico
Created June 20, 2012 07:35
Show Gist options
  • Save trico/2958648 to your computer and use it in GitHub Desktop.
Save trico/2958648 to your computer and use it in GitHub Desktop.
Añadir una clase para cada uno de los elemento de wp_nav_menu
<?php
function new_nav_menu_items($output) {
$idstr = preg_match_all('/<li class="page_item page-item-(\d+)/', $output, $matches);
foreach($matches[1] as $mid){
$slug = basename(get_permalink($mid));
$output = preg_replace('/page-item-'.$mid.'(| current_page_item)">/', 'page-item-'.$mid.' page-item-'.$slug.'">', $output, 1);
}
return $output;
}
add_filter( 'wp_list_pages', 'new_nav_menu_items' );
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment