Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created January 21, 2014 15:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kasparsd/8542235 to your computer and use it in GitHub Desktop.
Save kasparsd/8542235 to your computer and use it in GitHub Desktop.
Add destination domain as sanitized CSS class to every WordPress menu item
<?php
add_filter( 'nav_menu_css_class', 'menu_item_href_css_class', 10, 2 );
function menu_item_href_css_class( $classes, $item ) {
$url_domain = parse_url( $item->url, PHP_URL_HOST );
if ( $url_domain )
$classes[] = 'link-' . sanitize_title( $url_domain );
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment