Site logo

Archived topic

Display Author's social links on Author profile page

5 replies · Started by JC on June 4, 2021

Viewing posts 1–6 of 6

Hello,

I have GP premium and Yoast SEO premium and what I am trying to do is display the Author's social links on the profile page (Author Archive page).

What I have done is create a Hook;
ELEMENTS - New - Hook
Hook = generate_after_arhive_title
Display Urle: Arhcive Pages

So my placeholder text shows and then I realised I have no idea how to display the fields there and it's always on themes I use but this is GP so I probably have to use some PHP wit CSS for it but no clue how to do it. Any help would be appreciated ;-)

Hi David, good to read you again and thank you for the quick response.

I did find that article but it only includes for the site social links opposed to the social links on the author profile.

So when we complete author profiles and add Facebook, Twitter, Linkedin, Website etc, to have that display from the Author's account on his profile page.

I discovered they store the values in the author meta... so you 'should' be able to do this:

function get_yoast_socials() {
    // Create HTML variable
    $html = '';
    // Get author ID
    $author = get_queried_object();
    // Get yoast meta values for social links
    $twitter = get_the_author_meta( 'twitter', $author->ID );
    $facebook = get_the_author_meta( 'facebook', $author->ID );
    // Append HTML with social links
    $html = '<a class="social-link" href="https://twitter.com/' . $twitter .'" rel="nofollow" target="_blank">Twitter</a>';
    $html .= '<a class="social-link" href="'. $facebook .'" rel="nofollow" target="_blank">Facebook</a>';

    return $html;
}

add_shortcode('social_links', 'get_yoast_socials');

thank you David I am going to give that a go and I will let you know and also try find the rest of the social accounts and share the final version, thank you sooo much!

You're welcome

This archived topic is closed to new replies.