The general rule for bonus actions:
You choose when to take a bonus action during your turn, unless the bonus action's timing is specified, ...
If you take the Attack action on your turn, you can use a bonus action to try to shove a creature within 5 feet of you with your shield.
This is the only time in the book where the word "if" is used in conjuction with taking a bonus action. Almost all other references to conditional bonus actions use the word "when".
While you're raging, you can use a bonus action on your turn to knock a Large or smaller creature prone when you hit it with melee weapon attack." - pg. 50
When you use your action to cast a bard spell, you can make one weapon attack as a bonus action. - pg 55
When you use the Attack action, you can make one weapon attack as a bonus action - pg. 63
When you use the Attack action with an unarmed strike or a monk weapon on your turn, you can make one unarmed strike as a bonus action - pg. 78
When you use the Attack action and attack with a one-handed weapon, you can use a bonus action to attack with a loaded hand crossbow you are holding - pg. 165
When you take the Attack action and attack with only a glaive, halberd, or quarterstaff, you can use a bonus action to make a melee attack with the opposite end of the weapon. - pg. 168
When you hit a creature with an unarmed strike or an improvised weapon on your turn, you can use a bonus action to attempt to grapple the target. - pg. 170
And then we have Flurry of Blows which uses neither "if" nor "when" but "after".
Immediately after you take the Attack action on your turn, you can spend 1 ki point to make two unarmed strikes as a bonus action. - pg. 78
I believe that "if" and "when" are largely interchangeable in this case, and we shouldn't assume that Shield Master functions any differently from any of the features that specify "when".
One of the 5E developers, Jeremy Crawford, has stated on Twitter:
As with most bonus actions, you choose the timing, so the Shield Master shove can come before or after the Attack action.
If this is the case, then Crawford would appear to be saying that the timing doesn't matter on any of these features that only specify "when" or "if".
I am inclined to agree with Crawford's ruling. I do not believe "if" nor "when" are sufficient to specify timing on their own. It is very common for the rules to use the words "after" and "before" when they care about the specific timing of some type of action. I do not believe it is incongruous with either realism or the rules for a character to use his Action to attack and then bonus action shield bash prior to actually taking the attack granted by his choice of Action. After all, characters with Extra Attacks can move about the battlefield with their movement in-between their attacks!
Furthermore, in my personal experience as a player and a dungeon master, I prefer that the player be allowed to take his shield bash before attacking. This is more enjoyable for the player, who otherwise cannot benefit from his own shield bash without action surge. Worsening matters, turn order may allow the enemy to stand-up immediately after being knocked down, meaning the shield bash benefited no one! As far as game balance goes, I did not find this to be a concern as a player or DM; it certainly didn't inspire jealousy from other players, in either case.