Skip to content

Instantly share code, notes, and snippets.

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 cameronjonesweb/b0d636326550c642f970a42b86a88a84 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/b0d636326550c642f970a42b86a88a84 to your computer and use it in GitHub Desktop.
Add a location class to WordPress menus
<?php
/**
* Add a class with the menu location to the WordPress menu wrapper
*
* @param array $args Menu arguments.
* @return array
*/
function cameronjonesweb_add_location_class_to_menus( $args ) {
if ( ! empty( $args['theme_location'] ) ) {
$args['items_wrap'] = str_replace( '%2$s', '%2$s menu--' . sanitize_html_class( $args['theme_location'] ), $args['items_wrap'] );
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'cameronjonesweb_add_location_class_to_menus' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment