Reputation: 19
How to create a share link via whatsapp from a current url.
Hello, I have a website that has share buttons, facebook, twitter, pinterest, mail, but I want to replace two of those with whatsapp and instagram, for example I want the person who presses the share button via whatsapp to share that current url they are viewing At that moment, here I leave the code that comes by default, I would like to replace pinterest with whatsapp:
`
<a href="#" class="rz-close">
<i class="fas fa-times"></i>
</a>
<div class="rz-modal-heading rz--border">
<h4 class="rz--title"><?php esc_html_e( 'Share', 'routiz' ); ?></h4>
</div>
<div class="rz-modal-content">
<div class="rz-modal-append">
<div class="rz-modal-container rz-scrollbar">
<div class="rz-signin-social rz-mb-1">
<ul>
<li>
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink(); ?>" class="rz-button rz--gg" target="_blank">
<span class="fab fa-facebook rz-mr-1"></span>
<span><?php esc_html_e( 'Share with Facebook', 'routiz' ); ?></span>
</a>
</li>
<li class="rz-mt-2">
<a href="https://twitter.com/share?url=<?php echo get_permalink(); ?>&text=<?php echo urlencode( esc_html( get_the_title() ) ); ?>" class="rz-button rz--gg">
<span class="fab fa-twitter rz-mr-1"></span>
<span><?php esc_html_e( 'Share with Twitter', 'routiz' ); ?></span>
</a>
</li>
<li class="rz-mt-2">
<a href="https://pinterest.com/pin/create/button/?url=<?php echo get_permalink(); ?>&media=&description=<?php echo urlencode( esc_html( get_the_title() ) ); ?>" class="rz-button rz--gg">
<span class="fab fa-pinterest rz-mr-1"></span>
<span><?php esc_html_e( 'Share with Pinterest', 'routiz' ); ?></span>
</a>
</li>
<li class="rz-mt-2">
<a href="mailto:?&subject=<?php echo esc_html( get_the_title() ); ?>&body=<?php echo get_permalink(); ?>" class="rz-button rz--gg">
<span class="far fa-paper-plane rz-mr-1"></span>
<span><?php esc_html_e( 'Share by email', 'routiz' ); ?></span>
</a>
</li>
</ul>
</div>
</div>
</div>
<?php Rz()->preloader(); ?>
</div>
`
Upvotes: 2
Views: 4168
Reputation: 39
You can create such a button easily by modifying the following example:
https://api.whatsapp.com/send?text=<?php echo get_permalink();; ?>
Here in this link you can see that inside the text=
parameter, I'm passing the function get_permalink()
which you have already created. But you can use any text you like.
Upvotes: 3