Sunday, October 24, 2021

Directorist |Whatsapp Link | Single Listing Page As Custom Field

There is a number of default social media to integrate and use in directors in many ways. However, Whatsapp is not a default one. Although they are working on it to include WhatsApp as default in settings, we can use the WhatsApp redirect in Single listing page, Author Page, and All listing page.

Please follow the instructions below to include WhatsApp on the Single Listing page as a custom field.

1. Enabling the key field:

Please copy and paste the following code at the end of the "functions.php" file of the currently activated theme folder. 

Directorist | Enable Field Key



  1. add_filter('directorist_custom_field_meta_key_field_args', function ($args) {
  2.     $args['type'] = 'text';
  3.     return $args;
  4. });


2. Create a custom Textarea field:

Please create a custom Textarea field and make sure the key ( meta key ) is "custom-whatsapp".


Directorist |Whatsapp Link | Single Listing Page As Custom Field

3. Template Override:

Please read the template override documentation before you start this process. This will help you to understand how to override the templates properly.

Template Override Documentation

a) Override the single listing template: 

Please create a file "directorist/single/custom-fields/text.php" in your currently activated theme folder with the following code -


  1. <?php
  2. /**
  3.  * @author  wpWax
  4.  * @since   6.7
  5.  * @version 7.0.5.2
  6.  */
  7.  
  8. if ( ! defined( 'ABSPATH' ) ) exit;
  9. ?>
  10.  
  11. <div class="directorist-single-info directorist-single-info-text">
  12.  
  13.     <div class="directorist-single-info__label">
  14.         <span class="directorist-single-info__label-icon"><?php directorist_icon( $icon );?></span>
  15.         <span class="directorist-single-info__label--text"><?php echo esc_html( $data['label'] ); ?></span>
  16.     </div>
  17.     <?php if (isset($data['field_key']) && $data['field_key'] == "custom-whatsapp") : ?>
  18.     <div class="directorist-single-info__value">
  19.         <a target="_blank" href="https://wa.me/<?php echo str_replace(' ', '', $value); ?>"><?php echo esc_html( $value ); ?></a>
  20.     </div>
  21.     <?php else: ?> 
  22.     <div class="directorist-single-info__value"><?php echo esc_html( $value ); ?></div>
  23.     <?php endif; ?>
  24.    
  25. </div>

4. Output:

Then you should see the output like this on the single listing page when you enter a WhatsApp number on the field:

Directorist |Whatsapp Link | Single Listing Page As Custom Field


Please contact the Directorist Support Team if you need more help.


No comments:

Post a Comment