How to install my WhatsApp Widget in WordPress


Reading Time: 2 minutes

The whole installation process is explanatory with enough material to complete the integration of the graphic element in WordPress.

This is a new WordPress Website using our WhatsApp Widget. This is an amazing Website from Singapore related to food and sustainability. They promote a way to consume where the goal is to reach zero waste.

https://growerck.com/

These are the steps you need to install your WhatsApp Widget

  1. Copy the widget code

2. Inside your WordPress go to APPEARANCE

3. Click on WIDGETS


4. Find the Custom HTML


5. Select the FOOTER

6. Press on PERSONALIZE HTML


7. Paste the widget code ( do not put any title)


8. Save


9. Your Widget is ready ❗️


Multilingual support for WordPress & WhatsApp Widget

For Polylang:

<?php if(pll_current_language() == ‘en’){ ?>
    <!–  CÓDIGO DEL WIDGET –>
<?php } elseif(pll_current_language() == ‘es’){ ?>

    <!–  WIDGET SCRIPT –>    
<?php } ?>

For WPML

<?php if(ICL_LANGUAGE_CODE==’es’) { ?>
     <!–  CÓDIGO DEL WIDGET –>
<?php } elseif(ICL_LANGUAGE_CODE==’en’) { ?>
      <!–  WIDGET SCRIPT –>  
<?php } ?>

Adding the WhatsApp Widget in WordPress with ShortCode

Using the file functions.php from the active theme, we can create a shortcode using add_shortcode.


<?php function sc_tochat() {
    ob_start();
?>

<script defer src=”https://widget.tochat.be/bundle.js?key=ef8c9006-a28c-4bb4-a602-5caebffa34a0“></script>

<?php
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
add_shortcode( ‘tochat_widget’, ‘sc_tochat’ );

Once we have the shortcode we can add it anywhere in our website.

  • Using the theme editor: [tochat_widget]
  • In our template using do_shortcode:
    <?php echo do_shortcode(‘[tochat_widget]’) ?>