3

I'm using this code to generate the WhatsApp share button:

<a href="whatsapp://send?text=<?php echo get_the_title(); ?> <?php echo get_post_permalink(); ?>">Share via Whatsapp</a>

I want to add also ?utm_source=whatsapp in the URL.

How can I achieve this?

1

I guess you're using WordPress based on the get_post_permalink() so try replacing <?php echo get_post_permalink(); ?> with <?php echo get_post_permalink().'?utm_source=whatsapp'; ?> to append the attribute onto the link.

1
  • Hello, Thanks for your reply. I tried your code. It does append the attribute to the link... but... it doesn't autofill in Whatsapp, after you hit share, selected the contact, it just stays emtpy. The one that I provided does autofill the text in Whatsapp... but sadly with no utm in it, so no way of tracking it (or let's say not so easy). – user873041 Feb 5 '16 at 19:01
0
<a href="whatsapp://send?text=[TITLE] : [Link]?utm_source=site%26utm_medium=social_share%26utm_content=whatsapp" data-action="[Link]"></a>

This works for me

1
  • How is it "work"? Whatsapp contact opened - it is obvious. But how and where do you use utm parameters? – Eugene Sep 11 '20 at 16:53
-2

You should url encode the = to %3D and it will work. And any & to %26.

3
  • I agree that some escaping needs to be done, but I would think it would have to be anything within the post title and within the permalink URL. Escaping the equals that separates the parameter from the value would not be correct. – Stephen Ostermiller Oct 18 '16 at 16:30
  • Thanks for downvoting a correct solution. Give the explanation of the OP, replacing = with %3D solves his issue. We don't have more info. Assuming the function(s) also need escaping is based on nothing, who knows they are already escaped? – Peps Oct 19 '16 at 18:20
  • Maybe you can explain it further? It sounds like you are suggesting whatsapp://send?text%3DTHE+TITLE which makes what had been a text parameter with a value into a single parameter whose name includes the equals sign and value. – Stephen Ostermiller Oct 19 '16 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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