"Share on WhatsApp" link

4

Based on this code

        <li><a class="whatsapp" title="<?php esc_html_e( 'Compartilhar no WhatsApp', 'grandmagazine' ); ?>" target="_blank" href="whatsapp://send?text=<?php the_permalink() ?>&url=<?php echo get_permalink(); ?>"><i class="fa fa-whatsapp"></i></a></li>

Where am I going to err that does not work on page sharing?

It looks like this

whatsapp: // send? text = link

In the browser, but the page is left blank.

This is a code that works for Facebook

    <li><a class="facebook" title="<?php esc_html_e( 'Compartilhar no Facebook', 'grandmagazine' ); ?>" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink(); ?>"><i class="fa fa-facebook"></i></a></li>

Where is the error?

    
asked by anonymous 04.08.2018 / 18:26

2 answers

6

Usually the community tends to close this type of question (related to WhatsApp), erroneously in my opinion.

Related questions usually do not understand the API related to WhatsAPP's "share" function and its peculiarities, which are nothing different from other great services like Facebook, Twitter, etc ... that provide an endpoint for the user to share content and external information on the network.

Two perspectives should be noted here:

  • if the user is accessing from a mobile device
  • if the user is accessing from a desktop

WhatsApp endpoint accepts only two parameters: phone and text and both must have the content encoded, in your case using PHP would be something like

<?php echo urlencode(get_permalink()); ?>

It should be noted that the phone field should be in international format (country code + area code + phone number)

// Brasil DDD (RS) número (omitido por X)
5551XXXXXXXXX

Depending on the perspective (mobile or desktop) endpoind changes.

For a mobile navigation you should use the whatsapp://send? protocol that will open the application if it is installed on the user's device, otherwise it will open the system interface for the user to choose a application to open this type of protocol.

In desktop navigation you use the https://api.whatsapp.com/send? link that will go to the WhatsApp web application domain (PWA), if you have not previously used this application (not logged in) he will be informed of it.

This function does not send automatically, it opens a window for user confirmation. If it confirms then it opens the dialog where the user should then click the submit button.

If the phone parameter is suppressed, the WhatsApp application (desktop or mobile) will open a modal for the user to choose from for sending content, contact lists or even groups.

>

I do not think it's duplicate but surely your question may be related to another one here in the community to which I've already replied: Send a message to WhatsApp via site [closed]

It's worth taking a look at this once, the "magic" to draw a more correct approach happens in frontend (javascript).

This is my demo already published in the above question as related: DEMO

Source: link

    
04.08.2018 / 20:21
3

Friend, your error, and because this link will only work in mobile .. or it will only open if you are accessing this link with a mobile phone, with WhatsApp installed to work.

I hope I have helped.

    
04.08.2018 / 18:51