admin管理员组文章数量:1406035
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'] );
}
?>
本文标签: functionsAuthor social media aren39t shown on the page
版权声明:本文标题:functions - Author social media aren't shown on the page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744966074a2634955.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论