I am trying to add the slug of the linked page as a class on each menu item (for styling purpose).
I got half way there with this function, which adds the word "slug" to the class. Now I need to replace it with the actual slug of the linked page.
function add_target_class($output) {
$output = preg_replace('/class="menu-item/', 'class="slug menu-item', $output);
return $output;
}
add_filter('wp_nav_menu', 'add_target_class');
Thanks