I seem to run into this problem frequently and can never find a solution. I have a Wordpress site with a top navigation. Since this is in my header.php, and used on all page
You could use preg_replace() to add class="active"
like this:
ob_start();
echo '';
$output = ob_get_clean();
$pattern = '~- ~';
$replacement = '
- ';
echo preg_replace($pattern, $replacement, $output);