Add Social Media Links to the Author Profile in WordPress

Add Social Media Links to the Author Profile in WordPress

Do you want Add Social Media Links to the Author Profile in WordPress? The WordPress official author profile doesn’t have any social media integration field. In this article, We will teach you How to social media fields on a WordPress author profile.

Since Social media link is a vital part of the author’s profile. So, Every WordPress author profile needs its own social media links. In the modern world majority of people are connected to social media platforms. They express their joyousness and dejection here. Also, It can increase visitors.

Add Custom Field on Author Profile:

If You are using a plugin for author social links, they are provided a repeater field for this job. But We are not using a repeater field for that because it’s a bit complicated for you. We will show you the easiest way to do this job. In past, We have shown you “How to Add an Author Image in WordPress without a Plugin”.

Let’s add some fields for popular social media. Like Facebook, YouTube, Instagram, Pinterest, Reddit, LinkedIn, and Twitter.

Use this code on function.php

/*Add social field for author profile*/
function wpk_social_media_fields( $user ){
    $facebook = get_the_author_meta( 'wpk_author_facebook_url', $user->ID );
    $YouTube = get_the_author_meta( 'wpk_author_youtube_url', $user->ID );
    $Instagram = get_the_author_meta( 'wpk_author_instagram_url', $user->ID );
    $Pinterest = get_the_author_meta( 'wpk_author_pinterest_url', $user->ID );
    $Reddit = get_the_author_meta( 'wpk_author_reddit_url', $user->ID );
    $LinkedIn = get_the_author_meta( 'wpk_author_linkedin_url', $user->ID );
    $Twitter = get_the_author_meta( 'wpk_author_twitter_url', $user->ID );
    ?>
    <table class="form-table">
        <tr>
             <th><label for="facebook"><?php _e("Facebook URL"); ?></label></th>
             <td><input id="facebook" type="text" name="wpk_author_facebook_url" value="<?php echo esc_url($facebook) ?>" size="50" placeholder="Facebook URL"></td>
        </tr>
        <tr>
             <th><label for="YouTube"><?php _e("YouTube URL"); ?></label></th>
             <td><input id="YouTube" type="text" name="wpk_author_youtube_url" value="<?php echo esc_url($YouTube) ?>" size="50" placeholder="YouTube URL"></td>
        </tr>
        <tr>
             <th><label for="Instagram"><?php _e("Instagram URL"); ?></label></th>
             <td><input id="Instagram" type="text" name="wpk_author_instagram_url" value="<?php echo esc_url($Instagram) ?>" size="50" placeholder="Instagram URL"></td>
        </tr>
        <tr>
             <th><label for="Pinterest"><?php _e("Pinterest URL"); ?></label></th>
             <td><input id="Pinterest" type="text" name="wpk_author_pinterest_url" value="<?php echo esc_url($Pinterest) ?>" size="50" placeholder="Pinterest URL"></td>
        </tr>
        <tr>
             <th><label for="Reddit"><?php _e("Reddit URL"); ?></label></th>
             <td><input id="Reddit" type="text" name="wpk_author_reddit_url" value="<?php echo esc_url($Reddit) ?>" size="50" placeholder="Reddit URL"></td>
        </tr>
        <tr>
             <th><label for="LinkedIn"><?php _e("LinkedIn URL"); ?></label></th>
             <td><input id="LinkedIn" type="text" name="wpk_author_linkedin_url" value="<?php echo esc_url($LinkedIn) ?>" size="50" placeholder="LinkedIn URL"></td>
        </tr>
        <tr>
             <th><label for="Twitter"><?php _e("Twitter URL"); ?></label></th>
             <td><input id="Twitter" type="text" name="wpk_author_twitter_url" value="<?php echo esc_url($Twitter) ?>" size="50" placeholder="Twitter URL"></td>
        </tr>
    </table>
    <?php
}
add_action( 'show_user_profile', 'wpk_social_media_fields', 90 );
add_action( 'edit_user_profile', 'wpk_social_media_fields', 90 );

When you are using this code. The Seven fields have already been added on User > Profile (End of the page).

Save the Field

I hope the field is already visible. But it cannot store information. To store information in the custom field, We will use the personal_options_update and edit_user_profile_update WordPress default hooks.

Use This code in the function.php

function wpk_soical_media_author_fields_save( $user_id ){
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    update_user_meta( $user_id, 'wpk_author_facebook_url', $_POST['wpk_author_facebook_url'] );
    update_user_meta( $user_id, 'wpk_author_youtube_url', $_POST['wpk_author_facebook_url'] );
    update_user_meta( $user_id, 'wpk_author_instagram_url', $_POST['wpk_author_instagram_url'] );
    update_user_meta( $user_id, 'wpk_author_pinterest_url', $_POST['wpk_author_pinterest_url'] );
    update_user_meta( $user_id, 'wpk_author_reddit_url', $_POST['wpk_author_reddit_url'] );
    update_user_meta( $user_id, 'wpk_author_linkedin_url', $_POST['wpk_author_linkedin_url'] );
    update_user_meta( $user_id, 'wpk_author_twitter_url', $_POST['wpk_author_twitter_url'] );
}
add_action( 'personal_options_update', 'wpk_soical_media_author_fields_save', 90 );
add_action( 'edit_user_profile_update', 'wpk_soical_media_author_fields_save', 90 );

It’s okay now field will save. Now one question is in front of us.

How to Get User Profile Social Links?

We have created a social link field recently. If you want a profile social URL. Look code below.

    $facebook = get_the_author_meta( 'wpk_author_facebook_url', $user->ID );
    $YouTube = get_the_author_meta( 'wpk_author_youtube_url', $user->ID );
    $Instagram = get_the_author_meta( 'wpk_author_instagram_url', $user->ID );
    $Pinterest = get_the_author_meta( 'wpk_author_pinterest_url', $user->ID );
    $Reddit = get_the_author_meta( 'wpk_author_reddit_url', $user->ID );
    $LinkedIn = get_the_author_meta( 'wpk_author_linkedin_url', $user->ID );
    $Twitter = get_the_author_meta( 'wpk_author_twitter_url', $user->ID );

Note: Every variable will return a social media URL.

Conclusion

Marketing and Connectivity is the most essential part of online activities. Everyone in the IT industry should act on social media platforms to know about people’s needs. I hope now you can Add Social Media Links to the Author Profile in WordPress.

I hope you like this article. If you have any problem or question, Please comment below.

See More:

How to Add an Author Image in WordPress without a Plugin

Leave a Reply

Your email address will not be published. Required fields are marked *