WordPress links/bookmarks – need to urlencode because spaces are getting stripped

WordPress is stripping spaces out of links.

For example putting this into the web address of a new link:

mailto:[email protected]?subject=Hello there

and saving results in this:

mailto:[email protected]?subject=Hellothere

I know that a space is %20 but my clients can’t be expected to use this. Plus they may be uploading PDFs/Word documents with spaces in the filename and copying and pasting the link.

How can I remedy this? I know I have to use urlencode, however I don’t really want to edit the core wordpress admin, because on upgrading I’ll have to change it again. However, I will do if its the only way (having a look I can’t seem to find a hook or anything that will let me do this!), but I just can’t figure out where to put it.

Thanks for any/all help you can give me.

1 Answer
1

You can use the antispambot() function for this.

Example:

<a href="https://wordpress.stackexchange.com/questions/22957/<?php echo antispambot("mailto:[email protected]?subject=Hello there'); ?>">Some link text</a>

Leave a Comment