Automatically adding Simple Social Bookmarks plugin to your posts

My Simple Social Bookmarks plugin is incredibly powerful. However, if you don’t have coding skills or access to your theme files then adding it is rather difficult.

If you’re in this situation, then here’s the solution (in a future release of the plugin I’ll automate this)…

Open up the functions.php file in your theme folder and add the following lines…

// Add to Post

function add_ssb_to_post( $content ) {

    // If a single post or page, add Social Bookmarks

    if ( ( is_single() ) or ( is_page() ) ) {
        if ( function_exists( 'simple_social_bookmarks' ) ) {

            // If URL Shortener plugin exists generate a short URL for the page

            if ( function_exists( 'simple_url_shortener' ) ) {
                $shorturl = simple_url_shortener( '', 'service=bit.ly' );
            } else {
                $shorturl = '';
            }

            // Add Social Bookmarks to bottom of post

            $content .= '<p align="center">' . simple_social_bookmarks( '', $shorturl ,'', '' ) . "</p>n";
        }
    }
    return $content;

}
add_action( 'the_content', 'add_ssb_to_post' );

I know it seems quite long but it has assorted checks to ensure that the plugin is active PLUS it will integrate Simple URL Shortener in as well. You’ll need to change the Simple URL Shortener parameters as appropriate (it’s currently set to use bit.ly) as well as Simple Social Bookmarks. I’ve also set up some CSS to centre the resulting bookmarks on the screen.

When done, you should have your social bookmarks added to the bottom of every post and page after the content.

In

25 responses

  1. Thanks for this David i have few more questions…i think that google+ doesnt work becouse i clicked to google+ and that didnt do nothing i also check my google+ posts there is nothing.Did i miss anything?Also would that code work in child theme function.php? I can try becouse im running buddypress with child theme or to wait answer?

    1. There is a problem with the Google+ link which I will fix the next release.

      If using a child theme you can add this to the main or child theme – either should work (but don’t add it to both!).

      David.

      1. In fact, I’ve decided to release an interim version to fix Google+ and also an issue with child themes (it wouldn’t get the images from the right theme!).

        It should be appearing in WordPress.org within the next half hour!

        David.

        1. aleksandar avatar
          aleksandar

          Great job 🙂 i know that making control panel option is borring but always will be users like me who will stumble somewhere in middle 😛 i can give some CSS suggestion if you like its cross my mind while i was working on website if you interested?

          1. aleksandar avatar
            aleksandar

            I haved problems with some hackers tonight so i didnt sleep all night those sc… hacked my hosting provider and put some basic page with nonsence with some stupid things and not just to me there was maybe 200 domains also but i was online and that was last 5 min.Before 6 7 days also with some plugin i get some cloakin malware that redirect from google my domain to some malware site.is it possible that wordpress is that much full with holes or i just imagine that?

          2. Sure – I’m always happy to receive help and advise!

            David.

          3. what do you think about very large social bookmarks icons?for example 60×60 or more but instead of jumping up animation to be like you open the door?sometning like this http://www.youtube.com/watch?v=c3wHB6mOMBs&feature=player_embedded that is great for black background but for white we could use borders during animation to be viewed nice and maybe becouse of size of icons to ass also border radius and text could be for example Click to share or Click or whatever.Im using Boxer plugin for my website you can see it if you have time http://www.velikisiljegovac.com on homepage and i will try to do same thing like this.What you think about that?

          4. I generally leave it up to the user to decide on their own styling – however, if there’s any you can provide I’ll be happy to include them in any release.

            David.

          5. aleksandar avatar
            aleksandar

            I put more then 2 links in previous post so probably is marked as spam 😉

          6. aleksandar avatar
            aleksandar

            I just removed old code and update plugin and i put code for other then default icons but icons dont show up just text links // Add to Post
            function add_ssb_to_post( $content ) {
            // If a single post or page, add Social Bookmarks
            if ( ( is_single() ) or ( is_page() ) ) {
            if ( function_exists( 'simple_social_bookmarks' ) ) {
            // If URL Shortener plugin exists generate a short URL for the page
            if ( function_exists( 'simple_url_shortener' ) ) {
            $shorturl = simple_url_shortener( '', 'service=bit.ly' );
            } else {
            $shorturl = '';
            }
            // Add Social Bookmarks to bottom of post
            $content .= '' . simple_social_bookmarks('','','','iconfolder=32x32&default=off&facebook=on&twitter=on&wordpress=on&googleplus=on&myspace=on&yahoomail=on&gmail=on&email=on&&target=_blank') . "n";
            }
            }
            return $content;
            }
            add_action( 'the_content', 'add_ssb_to_post' );
            should i remove url shortener code?

  2. Where is the 32×32 folder located? If it’s in the main theme folder it needs to be in the child theme.

    David.

  3. aleksandar avatar
    aleksandar

    hehehehe im too tired i tottaly forget that we have been talking for child theme.I will put icon folder in child theme but i put function code in main theme function becouse folder with icon was in main theme directory.Sorry 🙂 i will try to modify CSS for those larger icons and test it to see how will react in live and if i succed i will pass to you.

  4. aleksandar avatar
    aleksandar

    I finnaly made it.I put in both parent and child theme icons and didnt worked i tryed parent theme functions also didnt worked then i tryed child theme functions to put code same thing then i removed from this line $content .= '' . simple_social_bookmarks( '', $shorturl ,'', '' ) . "n"; next code $shorturl , and started to work now just to check from which folder he is taking icons i will rename one of icons folders to check.

  5. Ha its getting icon from child theme yeahhh baby so officialy buddypress working you can see my favourite post there Novak Djokovic interview and photos after he became no1 on planet.Buddypress is little weird becouse they keep parent theme in buddypress plugins directory and my child theme is wp-content themes folder and that is two very different locations if we compare WP ussual parent/child themes and best thing is that work.Thanks alot mate 🙂

  6. aleksandar avatar
    aleksandar

    google+ says: You supplied an invalid value for the parameter ‘dest’.
    +__+

    1. It works fine for me – I’m wondering if you have caching turned on which means it’s not using the changed Google+. If you hovver over the Google+ icon is the URL for addtoany.com? If not, it’s not using the changed code.

      David.

  7. I just read that Google+ still didnt release Google API but they mention something about circles.Guess we will wait that API 🙂

  8. Its …api.addthis.com

  9. How can i change that? 🙂

    1. This appears to be a problem with Addthis. To get around this you will need to open the file define-bookmarks.php in the plugin folder and find the following line…

      array('Google+','googleplus','google_plusone','','google_plus',''),

      Change it to…

      array('Google+','googleplus','','','google_plus',''),

      This will prevent Addthis from handling the Google+ link.

      1. Thanks for tip 🙂

  10. Is there any chance to get this bookmarks show on bbPress forums,topics or posts?

    1. I don’t use bbPress myself, so this is something you’d need to take up with them. However, I’m happy to add this to the list of things to look into myself for a future release.

      David.

  11. Hi David,

    First off, thank you for such a sweet plugin (gave it 5 *’s on WordPress.org and reported it working for WP 3.3.2). What I am most impressed by is the extremely small footprint your plugin has. Kudos!

  12. Forgive my ignorance but if I add the code to the PHP file, will it not be over-written when the theme is updated?

    I can understand enough to tweak the code as required but as a newbie, placing the code is a little obscure. The “Other Notes” comment on WP Plugins site about “should be within “the loop”” is clear as mud.

    Am I to understand you need the function per the article here, then the function call in the code of the post? And the second is where site and other listed variables are set?

    And both would have to be edited back in when there is updates? The other Social Media plugins I’ve looked at were buggy and bloated or abandoned.
    Thanks!

Leave a Reply to alex80ksCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from David Artiss

Subscribe now to keep reading and get access to the full archive.

Continue reading