I'm trying to show the authors social medias on the page but they aren't showed at all.
Here is the code that I have so far
$website = $user->user_url;
if($user->user_url != '') {
printf('<a href="%s">%s</a>', $user->user_url, '<i class="icon-home"></i>');
}
$twitter = get_user_meta($user->ID, 'twitter_profile', true);
if($twitter != '') {
printf('<a href="%s">%s</a>', $twitter, '<i class="icon-twitter"></i>');
}
$facebook = get_user_meta($user->ID, 'facebook_profile', true);
if($facebook != '') {
printf('<a href="%s">%s</a>', $facebook, '<i class="icon-facebook"></i>');
}
$google = get_user_meta($user->ID, 'google_profile', true);
if($google != ''){
printf('<a href="%s">%s</a>', $google, '<i class="icon-google"></i>');
}
$linkedin = get_user_meta($user->ID, 'linkedin_profile', true);
if($linkedin != ''){
printf('<a href="%s">%s</a>', $linkedin, '<i class="icon-linkedin"></i>');
}
Only the Website
is visible. Any idea where is the mistake here?
I'm trying to show the authors social medias on the page but they aren't showed at all.
Here is the code that I have so far
$website = $user->user_url;
if($user->user_url != '') {
printf('<a href="%s">%s</a>', $user->user_url, '<i class="icon-home"></i>');
}
$twitter = get_user_meta($user->ID, 'twitter_profile', true);
if($twitter != '') {
printf('<a href="%s">%s</a>', $twitter, '<i class="icon-twitter"></i>');
}
$facebook = get_user_meta($user->ID, 'facebook_profile', true);
if($facebook != '') {
printf('<a href="%s">%s</a>', $facebook, '<i class="icon-facebook"></i>');
}
$google = get_user_meta($user->ID, 'google_profile', true);
if($google != ''){
printf('<a href="%s">%s</a>', $google, '<i class="icon-google"></i>');
}
$linkedin = get_user_meta($user->ID, 'linkedin_profile', true);
if($linkedin != ''){
printf('<a href="%s">%s</a>', $linkedin, '<i class="icon-linkedin"></i>');
}
Only the Website
is visible. Any idea where is the mistake here?
1 Answer
Reset to default 0Try This for IF :
if(!empty($user->user_url)) {
// OUTPUT
}
All Code
$website = $user->user_url;
if(!empty($user->user_url)) {
printf('<a href="%s">%s</a>', $user->user_url, '<i class="icon-home"></i>');
}
$twitter = get_user_meta($user->ID, 'twitter_profile', true);
if(!empty($twitter)) {
printf('<a href="%s">%s</a>', $twitter, '<i class="icon-twitter"></i>');
}
$facebook = get_user_meta($user->ID, 'facebook_profile', true);
if(!empty($facebook)) {
printf('<a href="%s">%s</a>', $facebook, '<i class="icon-facebook"></i>');
}
$google = get_user_meta($user->ID, 'google_profile', true);
if(!empty($google)){
printf('<a href="%s">%s</a>', $google, '<i class="icon-google"></i>');
}
$linkedin = get_user_meta($user->ID, 'linkedin_profile', true);
if(!empty($linkedin)){
printf('<a href="%s">%s</a>', $linkedin, '<i class="icon-linkedin"></i>');
}
EDIT
Previously, you had to add code in the function according to your needs.
Example
<?php
//CREATE CUSTOM USER DATA
add_action( 'show_user_profile', 'facebook_custom_extra_profile_fields' );
add_action( 'edit_user_profile', 'facebook_custom_extra_profile_fields' );
function facebook_custom_extra_profile_fields( $user ) { ?>
<h3><?php echo esc_html__('Facebook URL','text-domain');?></h3>
<table class="form-table">
<tr>
<th><label for="twitter"><?php echo esc_html__('Facebook URL','text-domain');?></label></th>
<td>
<input type="text" name="facebook_profile" id="facebook_profile" value="<?php echo esc_attr( get_the_author_meta( 'facebook_profile', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php echo esc_html__('Please enter Facebook URL.','text-domain');?></span>
</td>
</tr>
</table>
<?php }
//SAVE CUSTOM USER DATA
add_action( 'personal_options_update', 'facebook_custom_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'facebook_custom_save_extra_profile_fields' );
function facebook_custom_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_user_meta( $user_id, 'facebook_profile', $_POST['facebook_profile'] );
}
?>