I have tried over the last 2 days without success to configure out the error of Telegram link on WP Single page. Here i1s what I have tried to achieve:
-
I removed and add some fields on user’s profile page of WP using php codes in functions.php:
if ( ! function_exists( 'modify_profile_fields' ) ) : function modify_profile_fields( $contactmethods ) { unset($contactmethods['facebook']); unset($contactmethods['youtube']); unset($contactmethods['linkedin']); unset($contactmethods['instagram']); unset($contactmethods['myspace']); unset($contactmethods['twitter']); unset($contactmethods['pinterest']); unset($contactmethods['soundcloud']); unset($contactmethods['tumblr']); unset($contactmethods['wikipedia']); $contactmethods['phone1'] = __( 'Phone 1' ); $contactmethods['phone2'] = __( 'Phone 2' ); $contactmethods['phone3'] = __( 'Phone 3' ); $contactmethods['telegram1'] = __( 'Telegram username' ); return $contactmethods; } add_filter('user_contactmethods','modify_profile_fields', 10, 1); endif;
They work perfectly correctly as intended.
- However, there is errors of displaying the value of Telegram field when I try to retrieve data of all 4 last fields which are phone1, phone2, phone3 and telegram1 with the following codes on Single page of WordPress (single.php):
a. Here is php part:
<?php
$curauth_id = get_current_user_id();
$author_phone1 = get_the_author_meta('phone1', $curauth_id); // Get data from phone1 field on profile page
$phone_display1 = preg_replace("|s|","",$author_phone1); // Remove white space from phone number
$telegram_input1 = get_the_author_meta('telegram1', $author_id);
$telegram_username1 = str_replace('@', '', $telegram_input1); // Remove @ from telegram username if it is entered by users
?>
b. Here is HTML part:
{if !empty($author_phone1)}
<button class="btn phone"><i class="fas fa-phone-alt" style="color:#AF0404 !important;"></i><a href="tel:{$phone_display1}" target="_top"> Call</a></button>
{/if}
{if $telegram_input1 != ''}
<button class="btn message"><i class="fas fa-envelope" style="color:#3282b8 !important;"></i><a href="https://t.me/{$telegram_username1}" target="_top"> Chat</a></button>
{/if}
The above HTML codes will display two buttons:
Call Chat
When hovering or clicking over Call button, it works perfectly as intended
When hovering or clicking over Chat button, it shows or go to: https://t.me/Array – it means the php codes above does not retrieve the value of Telegram1 field or something not right with curly codes?
Very appreciate any support.