Hi, how can I create a custom shortcode to remove all text after a comma from a text field? I'm outputting the custom post title, which is an address (for example 123 Main Street, City, State, Zip code), but on a list view on another page, I want to output just 123 Main Street. Thanks in advance for the help!
The best way to resolve this is as you say using a custom shortcode to trim the text. In this case we will make use of the explode function to convert the string to an array using the comma as a delimiter.
What this does is that we will get an array of text where we can trim off the specific text we want. In your case it will be the first segment.
I've crafted a custom shortcode below that should help you with this.
Add the following to your Toolset custom code settings at Toolset->Settings->Custom Code. Once you've done this please ensure that you've activated it.