It depends. If the Swiss Travel Pass entitles you to a 50% reduction for the route, you can buy a ½ fare ticket. Reductions of 25% (for example, for Jungfraujoch) can only be purchased at the ticket counter.
You can buy tickets in the SBB Shop (www.sbb.ch/en) or in the SBB Mobile app. If you buy them in the SBB Shop, first open a user account and make sure you are logged in during the purchase. You can then log in with the same account on the SBB Mobile app and see the tickets listed under “Tickets”. Make sure you select ½ fare when purchasing a ticket for a route where the STP grants 50% off.
See the validity map to find out where the STP is valid or entitles to buy tickets at reduced fare:
https://www.sbb.ch/en/tickets-offers/travelcards/area-validity-map.html