The *=
is a CSS wildcard selector. What it means is find me a href that contains a string in this case: #
character.
Unfortunately theres not a wild card that selects any old character in the string.
If all your links started with the same letter/string for example they were #section-X
then you could use:
a[href*="#s"]
Geeky info here:
http://www.w3.org/TR/selectors/#attribute-substrings
Alternatively if you can change the selector be more specific, and you could add multiple selectors to that filter:
add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
$elements[] = 'p > a[href*="#"]'; /* Only target A if direct child of P */
$elements[] = '.page-hero a[href*="#"]'; /* Target A if is inside the page-hero */
return $elements;
} );