如果出现以下情况,请尝试此操作:
if(!empty($user->user_url)) {
// OUTPUT
}
所有代码
$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.
实例
<?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\'] );
}
?>