I'm trying to inject data from a custom field text string in the middle of a manually coded html link URL to be used as a parameter, but because the database text includes spaces and commas, the link does not work properly.
Can you suggest a way I can make the output for a custom text field ignore the commas and replace the spaces with %20 for just this one output instance? I may need to to use the text data from that same custom field in another way at a later point, but was trying to avoid creating a duplicate custom field for the same info and having to add %20 in the text string manually.
Example:
<a href="hidden link field='address-parameter'][/types]" target="_blank" >Beachfront Units</a>
The 'address-parameter' custom field data holds a value like 'Charleston County, South Carolina, USA'
Is there a way to output the data just for this case to be 'Charleston%20County%20South%20Carolina%20USA'
Thank you for contacting us and I'd be happy to assist.
To achieve this, you can register a custom shortcode ( ref: https://codex.wordpress.org/Shortcode_API ), that gets the value from the target custom field and returns it using the 'urlencode' function ( hidden link ).
Next, please add "custom_URL_encode" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
After that you'll be able to use this newly registered shortcode, like this:
(This example targets the field with slug 'address-parameter', but you can also use it for other fields )
[custom_URL_encode field='address-parameter']
I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/
regards,
Waqar
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.