WP Authors Page Template With Social Media Links

This code is an extension of another post about how to create an author contributors page template.

The code adds extra user profile fields for social media links.

contact info

On top of this it uses the native Dashicons already included in WordPress.

Authors Template

Code Installation

There’s 3 blocks of code which need to be installed.

  1. Create a new file named contributors_page.php using a text editor like Notepad++ and copy the code under contributors_page.php into your new file. Save the file to desktop and upload to the root directory of your child theme.
  2. Copy the PHP code under functions.php and paste it at the end of your child themes functions.php file.
  3. Copy the CSS code under style.css and paste it at the end of your child themes style.css file before the start of your Media Queries section.
Update: This page template now only displays the social media icon if the field is populated. If not, it won’t display.

Note: The code lists all authors who are assigned the contributor role only & has been tested on the Genesis default theme. May need tweaking for use on other themes.

Related Posts


Comments

15 responses to “WP Authors Page Template With Social Media Links”

  1. thisisarp Avatar

    OK – got this working as a shortcode, woot! One thing is bedeviling me – I want to randomize it rather than have it ordered by the number of posts. It doesn’t seem like get_users has an option to randomize the order (for either order or orderby). How can I do that?

    Also, even though I’m using it in a widget as a shortcode, the output is display above the widget title. I have no idea how that is happening.

    1. Brad Dalton Avatar
      Brad Dalton

      You could replace get_users with WP_User_Query but that doesn’t seem to include the standard WP_Query Order & Orderby Parameters either, not sure why so i’ll see if i can find out for you.

      Maybe you are returning it before returning the widget?

      1. thisisarp Avatar

        I found a really simple way to randomize – before the foreach statement, I added this:

        shuffle( $contributor_ids );

        I found it by taking a look at the Author Avatars plugin to see how they did it. Maybe it’s an option you can add to your code 🙂

        On the shortcode being called before the widget, I’m not sure how that works – I’m still quite the noob.

        1. Brad Dalton Avatar
          Brad Dalton

          Cool.

          Haven’t seen that function before.

          Thanks for the great feedback.

    2. Brad Dalton Avatar
      Brad Dalton

      Try pre_get_posts as another function for RAND

    3. thisisarp Avatar

      And …. because I’m using a shortcode where the function is not returning a string, I had to use output buffering to get the widget title to appear above the shortcode output. Plus I figured out how to limit the results to 1 random contributor. Now to figure out the last steps of creating a custom profile field to upload images and to display those images…

  2. Josef Davies-Coates Avatar
    Josef Davies-Coates

    This is great, thanks!

    However, the social icons appear whether or not the relevant fields have any date input into them, which is a bit a problem (not everyone has relevant social links).

    I’ve not added any links for into the relevant profile fields for the vast majority or those contributors, and yet the social icons are displaying for everyone
    Any idea how I can change/ fix this?

    Thanks!

    1. Brad Dalton Avatar
      Brad Dalton

      You will need to modify the code to get it to do exactly what you want.

  3. Erica Mueller Avatar
    Erica Mueller

    Will this also be translated for Genesis? I noticed the page template code doesn’t look like the template code for a Genesis theme.

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Erica

      You can add translation if you like. http://codex.wordpress.org/Translating_WordPress

      There’s different ways to code templates.

      The reason i coded it this way is so it works with any theme.

    2. Brad Dalton Avatar
      Brad Dalton

      Just wrote the code specifically for Genesis. Thanks for the idea Erica http://wpsites.net/web-design/genesis-users-page-template/

  4. Davide Avatar

    Thanks a lot for this useful tutorial and scripts.
    Accept only a little suggestion also for your follower… I found the email to add http:// before then in functions.php modify the following line:
    [code]
    <a class="contributor-email-link" href="mailto:”>

    into the following:

    <a class="contributor-email-link" href="mailto:”>
    [/code]

    1. Brad Dalton Avatar
      Brad Dalton

      What is the difference?

  5. mariedenee Avatar
    mariedenee

    This is amazing. I however how two issues… all the links are defaulting to the site’s links or my links on my profile not theirs and in the array section, how do I edit out or edit in only certain contributors?

    1. Brad Dalton Avatar
      Brad Dalton

      Code modifications are not provided for free.

      I would need to inspect and test your code to see where you went wrong with the installation.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.