Implementing the share or follow links into a theme

Putting this plugin into a WordPress Theme

There are 7 ways of implementing this plugin directly into a theme, you can either use the simplified functions of the_share_links(), get_the_share_links(), my_share_links(), my_wp_ecommerce_share_links() and the much more complex social_links() and follow_links().

the_share_links() prints where it is placed a un-ordered <ul> list of links

    <?php the_share_links(); ?>

get_the_share_links() returns the content of un-ordered <ul> list of links as a variable

    <?php get_the_share_links(); ?>

These will only return the share links for Facebook, Twitter, Digg, Delicious and Reddit, with Icons and text in a row.

using my_share_links() in a theme will cause the system to display the icons/shares you have selected in the admin screen and will place them in a row in your theme.

    <?php my_share_links(); ?>

There are no arguments  for this function as it gets them all from the admin screen.  Please note that this function takes no notice of the excluded items and will appear in every location that you template allows no matter what the ID.

4. my_wp_ecommerce_share_links

my_wp_ecommerce_share_links() can be inserted into a WP-ecommerce theme at any location.  The main thing of this template tag is that it does not use the wordpress  get_permalink but uses the wpsc_the_product_permalink() and wpsc_the_product_title() to generate the correct links

    <?php my_wp_ecommerce_share_links(); ?>

Again there are no arguments with this function, you just have to place it where you want  the links to be.

5. Social Links

the much more complex but useable social_links($args)

    <?php

    $perma=get_permalink();
    $title=get_the_title();
    $postid = strval($post->ID);
    $args = array (
                'page_id' => $postid,
                'heading' => "1",
                'size' => "16",
                'list_style' => "icon_text",
                'direction' => 'down',
                'facebook' => 'yes',
                'twitter'=>'yes',
                'delicious'=>'yes',
                'digg'=>'yes',
                'reddit'=>'yes',
                'myspace'=>'no',
                'hyves'=>'no',
                'orkut'=>'no',
                'share'=>'yes',
                'page_title'=>$title,
                'page_link'=>$perma,
                'echo'=>'0',
                'facebook_share_text' => 'Recommend on Facebook',
                'stumble_share_text'=> 'Share with Stumblers',
                'twitter_share_text'=>'Tweet this',
                'delicious_share_text'=>'Bookmark on Delicious',
                'digg_share_text'=>'Digg this',
                'reddit_share_text'=>'Share on Reddit',
                'hyves_share_text'=>'Tip on Hyves',
                'orkut_share_text'=>'Share on Orkut',
                'myspace_share_text'=>'Share via MySpace',
    );
    social_links($args);
    ?>

what the arguments do

  • page_id ID of current post, use the $postid = strval($post->ID) as suggested
  • heading 0 = don’t show a heading, 1= show the heading
  • size can any of the follow 16, 24, 32, 48, 60
  • list_style can be “icon_text”, “iconOnly” or “text_only”
  • direction can be with ‘down’ or ‘row’. Down is a downwards list, row is on one line, best with icon only
  • facebook display the facebook link ‘yes’ or ‘no’
  • twitter display the twitter link ‘yes’ or ‘no’
  • delicious display the delicious link ‘yes’ or ‘no’
  • digg display the digg link ‘yes’ or ‘no’
  • reddit display the reddit link ‘yes’ or ‘no’,
  • myspace display the myspace link ‘yes’ or ‘no’
  • hyves display the hyves link ‘yes’ or ‘no’
  • orkut display the orkut link ‘yes’ or ‘no’
  • share display the word ‘share’ at the beginning of the list ‘yes’ or ‘no’
  • page_title the Title of the current post or page, use $title=get_the_title() as suggested
  • page_link the Permalink of the current page or post, use $perma=get_permalink(); as suggested
  • echo Set to 0 to print the element, 1 to return the variable
  • facebook_share_text lets you change the facebook share text away from the standard (don’t make it blank, use another list_style)
  • stumble_share_text lets you change the stumble upon share text away from the standard
  • twitter_share_text lets you change the twitter share text away from the standard
  • delicious_share_text lets you change the delicious share text away from the standard
  • digg_share_text lets you change the digg share text away from the standard
  • reddit_share_text lets you change the reddit share text away from the standard
  • hyves_share_text lets you change the hyves share text away from the standard
  • orkut_share_text lets you change the orkut share text away from the standard
  • myspace_share_text lets you change the myspace share text away from the standard

Important you don’t have to do all of these options, only the ones you want to change away from the norm. The listed one inside the PHP tags is the standard set.

4. Using the follow_links() function

There is also a follow_links() function that has many arguments for you to play with. As with the widget, the follow links will only display any links when told to


<?php
    $args = array(
              'size' => "16",
             'list_style' => 'text_replacement',
             'icon_set'=>'default',
             'direction' => 'down',
             'iconset'=>'default',
             'word_value'=>'follow',
             'word_text'=>__('follow:','share-and-follow'),
             'page_title'=>'',
             'page_link'=>''
             'echo'=>'0',
             'words'=>'long',
             'sidebar_tab'=>'tab',
            'add_follow_text'=>'true',
            'css_images'=>'yes',
            'follow_location'=>'right',
            'facebook_text'=>__('Become a Fan','share-and-follow'),
            'coconex_text'=>__('Connect with us','share-and-follow'),
            'plaxo_text'=>__('Join my address book','share-and-follow'),
            'vkontakte_text'=>__('Become Friends','share-and-follow'),
            'gowalla_text'=>__('Follow my actions','share-and-follow'),
            'xing_text'=>__('Connect with us','share-and-follow'),
            'digg_text'=>__('Digg my stuff','share-and-follow'),
            'soundcloud_text'=>__('Listen to my music','share-and-follow'),
            'vimeo_text'=>__('Watch my video','share-and-follow'),
            'dailymotion_text'=>__('Tune to my channel','share-and-follow'),
            'foursquare_text'=>__('Follow me on Foursquare','share-and-follow'),
            'lastfm_text'=>__('Check my tunes','share-and-follow'),
            'stumble_text'=>__('Follow my Stumbles','share-and-follow'),
            'twitter_text'=>__('Tweet with me','share-and-follow'),
            'tumblr_text'=>__('Tumblr.','share-and-follow'),
            'youtube_text'=>__('Subscribe to my Channel','share-and-follow'),
            'hyves_text'=>__('Become Hyves friends','share-and-follow'),
            'orkut_text'=>__('Become Orkut friends','share-and-follow'),
            'myspace_text'=>__('Become my MySpace follower','share-and-follow'),
            'yelp_text'=>__('Read Reviews','share-and-follow'),
            'newsletter_text'=>__('Join Newsletter','share-and-follow'),
            'linkedin_text'=>__('Connect with me','share-and-follow'),
            'flickr_text'=>__('See my photos','share-and-follow'),

            'xfire_text'=>__('Join me on a mission','share-and-follow'),

            'rss_text'=>__('RSS feed','share-and-follow'),

            'google_buzz_text'=>__('Join the conversation','share-and-follow'),

            'yahoo_buzz_text'=>__('Connect with me','share-and-follow'),

        );
follow_links($args);

?>
  • size is the size of the icons shown
  • list_style is the style of display "text_only", "icon_text" or "iconOnly"
  • direction is either 'down' or 'row'
 

38 Responses to Implementing the share or follow links into a theme

  1. Jen says:

    There wouldn’t be a handy simple function for follow, would there? I don’t actually want the tab, just the icons that I can insert into a specific location (by the search bar).

    • Jen

      the best option for you is to setup a new sidebar widget area next to your search button. With that setup you can use the follow widget to manage things nicely. There is a function but I expect this will be an easier way.

      You’ll need to edit 2 things to get a new sidebar setup, the functions.php file to allow the system to understand that there is a new sidebar available. And also to edit the place in your theme where you want it to be, to add the call to the sidebar.

      i.e. example functions.php

      register_sidebar(array('name'=>'sidebar-search',
      'before_widget' => '<div class="block">',
      'after_widget' => '</div>',
      'before_title' => '<h4>',
      'after_title' => '</h4>',
      ));

      i.e. put into header.php next to search area
      <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-search') ) ?>

      more info on this here…. http://www.blogohblog.com/adding-extra-sidebar-to-your-wordpress-theme/

      regards
      Andy

  2. Terry Yee says:

    hi, is there a way to incorporate into a template using the or similar, that outputs the settings from the Share and Follow Administration settings?

    or using the follow_links() function to add more items? in particular the email function?

    • Hey Terry,

      this is something I am looking at for the next release. First I have to bring down the size of the release in MB so that wordpress will zip it properly. This is gonna take some re-coding first ;)

      I have found during my own theme development that I’m looking for these tools also.
      regards
      Andy

  3. Sooda says:

    Hi Andy,

    Thanks for the handy plugin, i works like a charm on one site.
    I get on error when i activate the plugin on my ohter site. I get following error:
    Fatal error: Cannot redeclare my_post_limit() (previously declared in /home/sparen/public_html/functions.php:25) in /home/sparen/public_html/wp-content/themes/mimbo/functions.php on line 33

    Thanks!

    • Hey Sooda,

      Sorry for the late reply, been a little busy and not able to get to you sooner. The best way to take this forward is for you to tell me some things about your other site so that I can help you debug the problem. I expect the problem in somewhere in the theme’s functions.php file, so if you could let me know your Theme Name and what other plugins you are running, we will soon get to the bottom of it. If you want me to contact you off list for these details do let me know

      regards
      Andy

  4. Hein says:

    Hi Andy,

    I’ve just implemented using social_links($args);
    For some reason the statement
    ‘share’=>”no”,
    doesn’t work.
    My site is in Dutch, so I’d prefer to lose the word “share” altogether or change it to “deel” or something.

    Bedankt, fantastische plugin,
    Hein
    vovert.nl

    • Hey Hein

      As a quick fix, you might like to try

      my_share_links();

      And then in the admin screen setup “Deel Door :” or what ever it is you like for sharing.

      What this function does is take all of the settings from the admin screen and uses them to create the share links where ever in the theme you put it.

      And I will also look at the bug to fix it with the existing social_links() function.
      All the best
      Andy

  5. James says:

    Hi, I am using this plugin on my own site [http://www.timordei.org] and it is so brilliant that a good many of my clients want it as well. I installed it and thought I set everything up right… I mean, it works on my own site, but it ain’t going anywhere on this one [atl]
    Does the theme not match? Where should I go to put in some code? Any clues would be very welcome. Thanks!

  6. chocolate says:

    I’m using the to show the icons beneath the tags section instead of beneath the post but all the icons selected are not showing.

    I have selected facebook, twitter, stumble, bookmark, email, tumblr, myspace, digg, delicious, google buzz,

    but only delicious, digg, facebook, twitter and one I did not select Reddit are showing.

    any solution..?

  7. Alex says:

    Hi! Great plugin, but i cant make to work “share” part of it. I’m not using widget, but try to implement plugin with my theme (twenty_ten). When i insert in single.php file (represent a single post) nothing happens at all. I tried to insert this statement into footer.php – links are shown but not with settings i set in admin area. Is there additionsl code/parameters i should insert to make it work? Thank you.

  8. Alex says:

    Thank you for suh a rapid fix!
    Appreciate this.

  9. Jen says:

    Hi Andy,

    I’m also having the issue where I select the icons to show, but no matter what, it only displays Delicious, Digg, Facebook, Reddit and Twitter.

    I am using my_share_links();, as you suggested to user “chocolate” a couple of weeks ago.

    Any suggestions would be helpful.

    Thanks!
    Jennifer

  10. Jen says:

    Hey Andy,

    That works great! Thanks for being so reponsive!

  11. Joy says:

    I saw several comments about the share_links shortcode not working. I looked at the code and the parameters are incorrect on the add_shortcode function call. There are only 2 parameters and the second one is supposed to be a function name, not an array of args. Could be why it’s not working.

  12. Joy says:

    Sorry Andy, I think I misread your code (an array specifying a class function instead of just a function name).
    I got the shortcode to trigger, but it just inserted an empty list. I have set the options to “No” to disable the auto list at the bottom of the post, but does that affect the shortcode? Or do you have to put a link in for Follow even if you are only using Share?
    Sorry to be obtuse, but I don’t use the social sites myself and I’m just trying to add this for a friend. Your documentation page does not address these issues.

  13. Sigo says:

    Greetings! Of the functions you have listed on this page, I could not figure out which one (if any) to use for calling the Facebook Like button.

    The reason I ask is that I’m using another plugin, SecondaryHTML, and I find that when I indicated in the admin section to include top-right the Like button, the S&F plugin places the button a bunch more places in the sidebar where I cannot control the display with CSS.

    Thank you!
    -sigo

  14. JR says:

    I have not been able to get the hyperlinks on the “follow tab” to work with my “autofocus Plus” theme. It is a child of “thematic.” If I put the follow tab at the top or bottom it works, but not on the sides. Any ideas on why this is?

    Thanks,
    J.R.

    • andy killen says:

      JR

      It’s because the weird theme developer has decided to have a z-index for the wrapper. weird thing to do but hey who am I to complain!

      Anyhow you can either delete the z-index from line 48 of your themes CSS or you can add the following code into your “add your own CSS” section

      #follow {z-index:100}

      I’ve set it to 100 just incase the theme developer has had a funny turn and used it else where. Why they have is beyond me as it is not needed at all and does not work correctly on all browsers

      regards
      Andy

  15. Russell says:

    Hello Andy!

    I love your script!! I have a quick question if I may…

    Right underneath the posted dade ( Published on January 05, 2011 with No Comments )on my articles like:

    http://www.beta21.radiojunkee.com/2011/01/05/investment-group-has-plans-for-first-ever-edm-casino-in-las-vegas/

    Is there anyway I can have my share buttons to show underneath that at the top of the article?

    I have been trying for a few days to get them to post there but no dice so I figured I would write you to gain some help.

    thanks for the wonderful script!

    Russ

    • andy killen says:

      Russ

      Your best bet is to use the them tag <?php my_share_links() ?> inside your theme. The possible places that you would want to use it are

      index.php (blog page and default display page)
      page.php (default for pages)
      single.php (default for posts)

      What you want to look for using single.php as an example is to look for the_content() and place my_share_links() above it.

      i.e.

      <?php my_share_links() ?>
      <?php the_content() ?>

      regards
      Andy.

  16. Arron says:

    Hi, love the plugin!

    I have used the within my index.php and it works a treat. I was just wondering if I can get the Facebook Like and the Twitter tweet buttons using a similar tag? I have enabled them via the admin menu which puts them at the bottom of each post, but not on the list of posts when index.php is calling .

    Hope that made sense,

    Thanks,

    Arron

  17. Diederik says:

    Hi Andy,
    I implemented the php line in my index.php but have some trouble getting the icons to work as an inline item, meaning I’d like to put something behind it on the same line. Is it defined as a div somewhere? Can I solve this somehow?
    Thank you,
    diederik

    • andy killen says:

      Diederik

      If you watch the video on the share and follow page you will see that there is a “share text” item, why not use that? It can be plain text or html.

      regards
      andy

  18. Stephen says:

    Thanks for the extremely useful plugin. I especially appreciate the flexibility of your various functions. Awesome!

  19. Stef says:

    Hi!

    Is sit possible to use a piece of code, such as , to dislplay a Facebook recommend button and Twitter retweet button on my site?

    If I use the options in the Interactive Share Buttons menu, the buttons end up in my post. I want them to be under my post, together with the other share buttons.

    For an example go to: http://www.studiofets.com.

    Thank you very much in advance! I like this plugin very much!

    Thank you,

    Stef

Leave a Reply