最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Author social media aren't shown on the page

programmeradmin2浏览0评论

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?

Share Improve this question edited Nov 26, 2019 at 14:53 S.I. asked Nov 26, 2019 at 13:44 S.I.S.I. 1251 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Try 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'] );
}

?>
发布评论

评论列表(0)

  1. 暂无评论