Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Wordpress is stripping spaces out of links.

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

mailto:my@email.com?subject=Hello there

and saving results in this:

mailto:my@email.com?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.

share|improve this question
    
That's because the link you've given is invalid. You need to write spaces as %20 or +. There is not much one can do about. And don't urlencode the links, because the ? therein will get encoded as well for example. That would be counter-productive. –  hakre Jul 14 '11 at 16:19
    
I understand, but my client doesn't want to have to type %20 every time they want a space. :) –  Thomas Clayson Jul 14 '11 at 18:32
    
instead of urlencode (I take your point) I could use preg_replace("/ /","%20",$theurl); –  Thomas Clayson Jul 14 '11 at 18:33
    
I see, look what you can do about that. As invalid URLs are not expected to be valid, you need to look if and especially how you can turn an invalid URL into a valid one. But you've not given any specs which strategy you want to use for it. Urlencoding the whole input looks not promising in my eyes. –  hakre Jul 14 '11 at 18:34
    
Maybe you want to offer some comfortable dialog where you can enter the type of link (website, email) and the based on the type offer multiple fields (like subject for email) the user can enter values into? That dialog can then create the valid URL. –  hakre Jul 14 '11 at 18:35

1 Answer 1

You can use the antispambot() function for this.

Example:

<a href="<?php echo antispambot('mailto:my@email.com?subject=Hello there'); ?>">Some link text</a>
share|improve this answer
    
ah, you've misinterpreted unfortunately. this is the actual links section in the backend... –  Thomas Clayson Jul 14 '11 at 18:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.