getButterfly Logo

This WordPress plugin allows you to display your Klout score using the Klout API. With a minimal configuration, you will be able to display your Klout score using a shortcode in a post, page or widget.

The plugin can be further improved, such as adding transient (or fragment) caching or showing changes (increase or decrease) from yesterday, last week and last month (because the returned data includes all these).

Here’s the code, if you need it, and here’s the shortcode, packaged as a WordPress plugin:

function k2api_klout($atts, $content = null) {
    extract(shortcode_atts(array(
        'prepend' => '',
        'type' => 'score',
        'key' => 'kqu4t7p74bxq7skynmn7zdwu',
        'user' => 'getbutterfly',
    ), $atts));

    $url_user_id = 'https://api.klout.com/v2/identity.json/twitter?screenName=' . $user . '&key=' . $key . '';
    $data_user_id = json_decode((file_get_contents($url_user_id)));
    $klout_user_id = $data_user_id->id;

    $url_kscore = 'https://api.klout.com/v2/user.json/' . $klout_user_id . '/score?key=' . $key . '';
    $data = json_decode((file_get_contents($url_kscore)));

    if ($data) {
        $kscore = $data->score;
    } else {
        $kscore = "?";
    }

    $out = '';

    $out .= '<div class="klout-score">
        <p>' . $prepend . '<a href="https://klout.com/#/' . $user . '">' . round($kscore) . '</a></p>
    </div>';

    return $out;
}

add_shortcode('klout', 'k2api_klout');

Note that you will need a Klout developer account (free).

This is how you use it in a post, page or widget:

[klout type="score" key="kqu4t7p74bxq7skynmn7zdwu" user="getbutterfly" prepend="Klout Score: "]

Category: