URL encoded {} functions

I’d like to be able to use, for example, {post-title} but have it encoded.

Use case: I have a reply-by-email function on posts but I don’t use the post title as the subject because validation complains about the spaces in the mailto link. Maybe like {post-title-encoded} or something.

No problem, {post-title-urlencoded} is now a thing.

{post-title} = Your new post, hello
{post-title-urlencoded} = Your+new+post%2C+hello

If there are any other fields that you need urlencoded, just say the word.

1 Like

I might not be using the right terminology. I was looking for spaces replaced by %20” which I think (from a quick Google) happens through rawurlencode(). My mistake.

1 Like

Gotcha, sorry! I used urlencode() when I should have used rawurlencode(). Incidentally I believe the output is virtually identical except for the use of + for spaces. Just flipped it to the other function and now spaces are rendered as %20 as intended.

1 Like

Perfect, does exactly what I need. Thanks.

1 Like

Followup: I notice now that for titleless posts, the {post-title-urlencoded} function doesn’t include the truncation appendix.

1 Like

Thanks for catching that — can you confirm that you’re seeing it working as intended now?

Not at the moment, although I don’t know if I need to trigger a rebuild, since I call this from a snippet in configuration.

Anyway, having had a couple o rebuilds since you asked, it’s definitely not using the truncation appendix when warranted.

OK, hmm, sorry about that. Clearly I goofed something… can you point me to a URL on your weblog where you’re expecting to see it? That’ll help me as I try to iron it out. :smile:

For example, if you go to this titleless post and scroll down to “reply by email” where I use this to populate the subject field in the link.

1 Like

I think I got it this time. Sorry for the trouble!

1 Like

Yep all good, thanks.

1 Like

Oops! It’s appending it for titled posts, too.

Ugh, OK, sorry about that! Digging into it further; I’ve clearly goofed something up.

1 Like