you're reading...


Last.fm RPS WordPress Plugin












Note: if you have this error message shown inside the plugin :

Deprecated: Function split() is deprecated in
on line 120

Please change

$artist = split("_",$string);

on line 120 to

$artist = explode("_",$string);

Description : Its a widget plugin which collects data from Audioscrobbler web services and gets your last listened tracks and their album images. It works in PHP4 platforms and uses my simplexml class to collect data from Audioscrobbler.

Installation : The directory structure should be like this :

 --> wp-plugins/
	|-- lastfm_RPS/
		|-- noart.gif
		|-- simplexml.class.php
		|-- readme.txt
		|-- lastfm.css

Then just activate the plugin, go to Design-Widgets, add the widget where you want, write the username and widget title in the settings and save. That’s all.

Note : If your theme isn’t widget enabled, you can insert this plugin in your sidebar.php file or wherever you want like this :

<h3>My Last.fm</h3>

<?php lastfm_recent_sidebar([username],[songs to show],[timezone diff in seconds],[image position 'left' or 'right'],[The text at bottom of this widget],[enable cache 'true' or 'false'])?>


Download : You can get the latest release here : http://wordpress.org/extend/plugins/lastfm-rps/

Current Version : 1.1

Demo : You can see a working example in the middle sidebar at my homepage ;)

Whats New in Version 0.2?

  • Added option to define how many songs are displayed on the page
  • Seperated css file from code and added new “lastfm.css” file
  • Added different stylesheets to recently played songs
  • Changed the datetime display configuration like “x days y seconds and z minutes ago”
  • Changed the div’s into tables which are more reliable for different themes.
  • If the user hasn’t any wp_head() included in his/her theme’s header.php, this script checks and adds its css itself.

Whats the fixes in Version 0.3?

  • Added a neccessary fix for the time difference between server time and local time.
  • If there is a track played in the player which length is less than 4 minutes ,the script showed two recently listened songs, so this is fixed now.It only displays one.

Whats new in Version 0.4?

  • Added support for not widget-ready themes.
  • Added Screenshot
  • Updated Readme.txt

Whats the fixes in Version 0.5?

  • When no songs played for a long time or only played only one song, this script raised errors. This is fixed now.
  • Optimized the SimpleXML Extension for speed issues.

What’s added in v0.6?

  • Improved checking of album images.
  • If the feed item contains no album name, then directly shows default image.

What’s New in v0.7?

  • Added image positioning
  • Added optional Bottom Text
  • Removed the slashes before ‘ and “
  • Converted tables to css so you have all the control in lastfm.css
  • Added artist images support. Now it shows artist images when it can’t find the album image.

The changes in 0.8

  • Added Various Artists album image support
  • Added last.fm badge option
  • Improved options page
  • Added last.fm logos (you should use one)

The changes in 1.0.0

  • Added cURL and fopen support

The minor changes in 1.0.2

  • Added security to file reading function inside class.

The changes in 1.0.3

  • Empty images show up as last.fm image placeholders now.
  • Fixed the compatibility issue with wordpress 2.7 (Their compat.php broke one of my function and i renamed it.)
  • Thanks to Tom for informing me that last.fm started to use 64×64 images instead of 50×50. Thats also changed.

The changes in 1.1

  • Added caching support
  • Changed Last.fm API v1.0 code to v2.0 code
  • Fixed “Now Playing” code


198 Responses to “Last.fm RPS WordPress Plugin”

  1. It worked thank u very much

    Posted by Hubert | Thursday, April 2, 2009, 17:39
  2. It worked!!! Thank you so much, you’ve been very very kind.

    If you wanna take a trip on my blog (even if it’s in italian and you won’t understand nothing :P ) you’re welcome

    Posted by Andrè Nakamura | Friday, April 3, 2009, 01:41
  3. Thank you… I’d rather like to spend some more time on it (because of the Internet Explorer issues), but I can’t…


    Posted by Andrè Nakamura | Friday, April 3, 2009, 21:26
  4. Hello !!!! :)
    I am Piter Kokoniz. oOnly want to tell, that I like your blog very much!
    And want to ask you: is this blog your hobby?
    Sorry for my bad english:)
    Your Piter Kokoniz, from Latvia

    Posted by PiterKokoniz | Wednesday, April 8, 2009, 04:37
  5. G’day. Great plugin. Just wondering which lines of code would I remove so that it doesn’t load or display the album art? Also, which lines of code would I remove to remove the last.fm logo?

    Posted by Dan | Friday, April 10, 2009, 16:23
  6. 244 to 252 is for image loading
    255 to 258 is for image showing
    and line 478 is for the last.fm logo.

    I didnt test them just looked and wrote here.

    Posted by Taha Paksu | Friday, April 10, 2009, 16:36
  7. Thanks for the quick reply. I tried to delete even just the first part, and now my site doesn’t load, just white, but when the code is there, it loads.

    Posted by Dan | Friday, April 10, 2009, 16:52
  8. But deleting lines 478 and 479 do remove the last.fm logo successfully.

    Posted by Dan | Friday, April 10, 2009, 16:55
  9. you should remove this lines

    $albumimage = get_album_art(stripslashes($album->scalar),stripslashes($artist->scalar));
    $replace = array(” “,”&”,”/”);
    $with = array(“%20″,”%26″,”%2F”);
    $artist = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($artist))));
    $album = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($album))));
    $albumimage = get_va_album_art($artist,$album);


    [code]echo ‘<p class=”lastfm_recent_image lastfm-recent-‘.$position.'”>';
    echo ‘<a href=”‘.$feed->track->url.'” title=”Cover artwork for ‘.stripslashes(lastfm_recent_capitalize($track->name)).'”>';
    echo ‘<img src=”‘.$albumimage.'” alt=”Cover artwork for ‘.stripslashes(lastfm_recent_capitalize($feed->track->name)).'” />';
    echo ‘</a></p>';[/code]

    Posted by Taha Paksu | Friday, April 10, 2009, 16:58
  10. New version has been released. Please backup your CSS file before updating.

    Posted by Taha Paksu | Wednesday, April 15, 2009, 10:25
  11. Hi I am having a rather particular problem with my blog. I think I have already sent you a message about it before, but here goes anyway. The alt text displayed on the album art isn’t quite working correctly. Like I just listened to Guns N’ Roses – Chinese Democracy recently.. and it is showing the same album name for all the artists.

    Can you please help? Thanks.

    Posted by Aditya | Saturday, May 30, 2009, 19:36
  12. @aditya : I checked your site, and I think you are using a different plugin?

    Posted by Taha Paksu | Saturday, May 30, 2009, 21:36
  13. Apologies Taha. I was messing around with another plugin at the same time.
    Can you tell me how can I display the album art inline without the text, and how I can hide my profile information? Seems a bit complicated from the looks of it. All I want to show is album art, and the alt tags could display the information.. however at the moment it says “cover for..”. I have tried editing it, but to no avail.

    Posted by Aditya | Sunday, May 31, 2009, 17:38
  14. Hello, I’m trying to get the plugin integrated into my about page. My theme does not support widgets, and I’ve got the plugin on the page in the place where I want it, but the spacing and horizontal rules seem off. Can you point me in the right direction of what I need to change/delete to have everything line up properly? I also would like to remove the whole badge and just display the coverart, song title, artist, and time played. The screenshot that came along with the install file is very close to what I would like it to look like, or like Andrè’s http://www.beerdelirium.com/

    I appreciate any help you can give me, and thank you for the wonderful plugin.

    Posted by clay | Thursday, June 4, 2009, 12:23
  15. @clay: you need to play with the lastfm.css file to adjust the width,height etc.. and for the badge thing, open lastfm.php and near the end you should see;

    $options = array(
    ‘title’ => ‘Last.fm RPS’,
    ‘size’ => 10,
    ‘serversec’ => 0,
    ‘position’ => ‘left’,
    ‘text’ => ”,
    ‘showbadge’ =>true,
    ‘badgeposition’ => ‘top’,
    ‘badgeoptions’ => ”

    change these values to make it fit your needs.

    Posted by Taha Paksu | Thursday, June 4, 2009, 12:52
  16. I receive an error when is use your plugin. my last.fm profilename is felix-leiter . if i activate the plugin as a widget i receive this error: “This username does not exist, or the feed service is down.” when i use an nonexisting username i also receive this error. is there an problem with the minus in my profilname or do i have to active the “feed service”? an if i have to, can you tell me where i have to do this.

    best regards

    Posted by felix | Friday, June 5, 2009, 17:44
  17. OK. The problem is about your server. Your username doesn’t cause any problems. Check if your server supports the standart PHP XML extension.

    Create a php file and write this inside it:

    < ?php echo phpinfo();?>

    then upload it to your host and run that.look for the XML table and check if its active in the configuration list.

    Posted by Taha Paksu | Friday, June 5, 2009, 18:00
  18. hello,

    these are my the phpmyinfo from my hoster, which is bplaced.net.

    XML Support active
    XML Namespace Support active
    libxml2 Version 2.6.32
    XML-reader &-writer active
    DOM/XML enabled
    libXML support active
    libXML Version 2.6.32
    libXML streams enabled

    i guess “XML support active” is what matters but it doesn’t work somehow. :(

    best regards

    Posted by felix | Friday, June 5, 2009, 21:18
    • ok. lets try this. open an empty php file on your server and try this code :

      include_once “simplexml.class.php”;
      $sx = new simplexml;
      $results = $sx->xml_load_file(“http://ws.audioscrobbler.com/1.0/user/felix-leiter/recenttracks.xml”);
      echo “<pre>”;

      Posted by Taha Paksu | Saturday, June 6, 2009, 11:23
  19. hello,

    i get these result from your code:

    “Parse error: syntax error, unexpected T_CLASS in /users/leiter/www/wordpress/test.php on line 2″

    these are the phpinfo results:
    Simplexml support enabled
    Revision $Revision: $
    Schema support enabled

    after changing “simplexml.class.php” to “simplexml.php” in line 2 I get another pharse error.
    “Parse error: syntax error, unexpected ‘:’ in /users/leiter/www/wordpress/test.php on line 4″
    my php version is 5.2.8

    Best Regards

    Posted by felix | Saturday, June 6, 2009, 12:00
  20. Hi! I’m trying to use this widget in my blog and I get the following error in the sidebar (after which clickable links to the music are there): Warning: gzinflate() [function.gzinflate]: data error in /home/passcreek/www/delilahmused/wp-includes/http.php on line 1787. What am I doing wrong? Thanks so much for your help.


    Posted by DelilahMused | Thursday, July 23, 2009, 20:43
  21. Doesnt work in wordpress 2.8x :(

    Posted by bigbrovar | Tuesday, September 22, 2009, 07:55
    • @bigbrovar : this site uses WP 2.8.4 and it works on it. what is the error?

      Posted by Taha Paksu | Tuesday, September 22, 2009, 23:12
      • “This username does not exist, or the feed service is down. ” that is what i get when i install it. am trying to run it on my localhost (ubuntu 9.04) what gives?

        Posted by bigbrovar | Saturday, September 26, 2009, 01:25
        • does your username contain uppercase characters? What’s your username? I’ll try myself. On the other hand, you may not have the PHP’s XML extension installed on your localhost. That might be the problem too. Check it with phpinfo() function. Is there a “XML” component installed on the list?

          Posted by Taha Paksu | Saturday, September 26, 2009, 15:18
          • my username on lastfm is bigbrova and phpinfo showed that XML is enabled and active. How there the widget work, will it for example work if am behind an http proxy? my localhost is behind an http_proxy so i had to add the proxy parameters to wordpress config which works fine for other internet aware widgets

            Posted by bigbrovar | Sunday, September 27, 2009, 03:14
          • Tried it again and i observed the following:

            The page takes blog page takes an incredible amount of time to load even though its on localhost and when it loads i get this “This username does not exist, or the feed service is down.”

            however if i disable the plugin. the page loads faster like it should.

            Posted by bigbrovar | Sunday, September 27, 2009, 03:26
          • that’s because this plugin fetches a xml file from last.fm.. try it again when you upload your site on a host.

            Posted by Taha Paksu | Sunday, September 27, 2009, 19:57
          • Hey mate I finally uploaded my blog onlone and it still doesnt work still says This username does not exist, or the feed service is down Just thought to let you know

            Posted by bigbrovar | Wednesday, October 21, 2009, 14:30
  22. So, i have a problem with the times sometimes when i listen to tracks, is see this -1d,23h and 58m ago for example offcourse.
    What the problem? Can it be fixed? I really want it to work properly!

    Posted by Bart | Wednesday, October 7, 2009, 22:42
  23. Really great plugin ! very good looking, Thank you …

    Posted by pled | Sunday, December 6, 2009, 14:18
  24. Hello! I love your plugin, but have made one adjustment that you might like to add to the main version. In lastfm.php, I have adjusted my lastfm_datediff function to account for songs that are currently being listened to. These songs will have a $dateDiff of zero or less. My modified function looks like this:

    function lastfm_datediff($date,$ret = 0,$serversec,$recentdisplayed){
    $now = time();
    $dateDiff = $now – $date + $serversec;
    $fullDays = floor($dateDiff/(60*60*24));
    $fullHours = floor(($dateDiff-($fullDays*60*60*24))/(60*60));
    $fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);
    if($dateDiff =4) return “$fullMinutes minutes ago”;
    if($recentdisplayed) return “$fullMinutes minutes ago”;
    if($ret) return “recent”;
    return “just listened”;

    where I’ve added the line: if($dateDiff <= 0) return "listening now";

    Posted by Ryan Cain | Monday, December 7, 2009, 09:22
  25. I can’t get the plugin to pull my song info. Do I have to scrobble from a local player or does it pull info from the online listening of last.fm. Want to make sure I cover my bases. Plugin looks great though.

    Thanks in advance.

    Posted by Neal | Sunday, December 20, 2009, 19:09
    • what exists in your personal profile page as listened or listening is displayed in this plugin. the answer is both you are listening locally and submitted to last.fm and you listen on the last.fm radio should be displayed here. and if you didnt listen to a song for a while maybe it wont show any songs on your profile.

      Posted by Taha Paksu | Monday, December 21, 2009, 00:45
  26. My songlist isn’t showing up correctly – it’s all jumbled up. Can anyone help?? I’m using WP 2.9.


    Thanks x

    Posted by Lizzie | Wednesday, December 23, 2009, 15:17
  27. @Bart:

    I fixed this problem on my site:

    Search this line:
    $fullMinutes = floor(($dateDiff-($fullDays*60*60*24)-($fullHours*60*60))/60);

    Under this, add a a new line:
    if($fullDays == -1) return “now playing”;

    Its works fine. ;)

    Posted by Csabi | Sunday, January 10, 2010, 15:11
  28. hi,
    thats because the last.fm server’s time is different from your hosting server’s time. There’s a box in the plugin’s configuration labeled “server time difference” so you can set the difference there, for example the song you are listening is displaying like this :”-1d 23h 55m ago” this means your server’s time is about 5 minutes = 300 seconds different from last.fm server’s time. you should set the value 300 or maybe 330 there and try again.

    Posted by Taha Paksu | Friday, May 21, 2010, 18:20
  29. There is an issue with the formatting the new ‘Twenty Ten’ default theme in the new version of WordPress 3.1. Can you see if you can fix it. You can see the problem at my website:


    Otherwise this is really excellent. I love the CD album covers.

    Posted by Olly | Tuesday, March 1, 2011, 20:55
  30. I cant use your plugin, it either shows your profile (nice taste by the way) or I get an error message saying:

    Allow_url_fopen: 1
    Warning: file_get_contents(http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=Hody72&api_key=pdv4w446gwfhkmjrphu433zj&limit=10) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /var/www/vhosts/hody.de/httpdocs/wp-content/plugins/lastfm-rps/simplexml.class.php on line 47
    This username does not exist, or the feed service is down.

    Username is Hody72 but the API key is another one – how can I fix this, please please help

    Posted by Hody | Sunday, March 13, 2011, 03:41
  31. Beautiful plugin – thank you very much for creating this!

    Posted by Simon | Sunday, July 3, 2011, 03:32
  32. Hiya, Can this RPS player be used in a normal custom built php or html website?

    Posted by Austin Maguire | Monday, July 11, 2011, 17:28
  33. Hi Taha,

    Is it possible to put the last fm music widget into a regular html/php website? I would like to put the “Last.fm Recently Played Songs v1.1 Plugin” from this wordpress site: http://www.ventolin.org onto my website. Is this possible?



    Posted by Austin Maguire | Thursday, July 14, 2011, 18:58
  34. I’m getting this error:

    Warning: file_get_contents(http://ws.audioscrobbler.com/1.0/artist/Dylan+Campbell+%2B+Christine+Spilka/similar.xml) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Resource Not Found in /home/wp-content/plugins/lastfm-rps/simplexml.class.php on line 46

    How can i fix this? Thanks! Great plugin otherwise!

    Posted by jeremy | Saturday, May 5, 2012, 09:18
  35. Hey there!

    I seem to be getting the following error — may you help?

    Catchable fatal error: Object of class stdClass could not be converted to string in /home/exit3/public_html/exit3/wp-content/plugins/lastfm-rps/lastfm.php on line 190


    Posted by Brian Schroeter | Saturday, May 26, 2012, 20:20
  36. try replacing

    $album = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes($album))));


    $album = rawurlencode(utf8_encode(str_replace($replace,$with,stripslashes((string)$album))));

    on line 190.

    Posted by Taha Paksu | Sunday, May 27, 2012, 16:43
  37. Hey, I’m getting an error when I try and install it :(
    All other plugins install fine but for some reason this won’t, i’ve had it installed before, but changed host and updated wordpress. Any ideas?

    Plugin could not be activated because it triggered a fatal error.
    “Parse error: syntax error, unexpected ‘}’ in /var/www/vhosts/taktak.co.uk/httpdocs/wp-content/plugins/lastfm-rps/lastfm.php on line 449″

    Posted by TAKTAK | Monday, June 25, 2012, 22:42
  38. Re-download the package and re-install it. And tell me what happens.

    Posted by Taha Paksu | Thursday, June 28, 2012, 22:27
  39. Tried deleting and reinstalling to no avail, still hit the same error. Updated WP to 3.4.1 and the error is still the same :(

    Posted by TAKTAK | Friday, June 29, 2012, 20:30
  40. Ok, the files now I’m using are packed at http://www.tahapaksu.com/lastfm-rps.rar download and try it. if it doesn’t work, there might be something wrong with your wp installation. My WP version is 3.4.1 too.

    Posted by Taha Paksu | Saturday, June 30, 2012, 18:14
  41. I like your plugin best out of many I tried, but it sometimes shows one more item than what I have set in “list size” If I set list size to four, sometimes it will show five items, and so on. Any fix for this?

    At first I had the plugin set to show my user profile/badge. This worked fine when I viewed it on my desktop browser, but in Safari on iOS, the badge text was overlapping the image so I had to take it off. Since I couldn’t “inspect elements” on my iPad, I wasn’t able to figure out how to modify the CSS to prevent this.

    Does caching mean that when Last.FM’s site is running slow or down, it won’t affect the loading of my site? This is a problem I was having with other LastFM plugins I tried.

    Posted by Sue | Monday, August 6, 2012, 21:38
  42. Hi Sue, thanks for trying my plugin first. Second, I didn’t catch this bug before and I’m not developing this plugin further. That was written 4 years ago. The overlapping issue would be fixed with CSS I think. And caching is saving the response from last.fm server to a file and using it for about 3-4 minutes for every request. When the cache expires, It’ll load a newer version into the cache file, so it’ll improve speed and will reduce unnecessary api calls to last.fm.

    Posted by Taha Paksu | Monday, August 6, 2012, 23:55
  43. Sorry, I don’t have much time to work with this plugin. Maybe later (don’t know when) I’ll rewrite it with new features. So if you want some extra features, feel free to post here. And thanks for using it.

    Posted by Taha Paksu | Tuesday, August 7, 2012, 23:47
  44. Thanks for informing me about that. I’ll prepare an update with the 64px images added.

    Posted by Taha Paksu | Thursday, April 9, 2009, 15:30
  45. I’m not great with this whole scripting thing. But I know enough to that I was able to change the album overlays. I got them to show up the way I want them however I can’t seem to get the artist and playback info to display the right way. Can you help?

    Here is a pic of what it looks like. Thanks.


    Posted by Mel | Thursday, June 30, 2011, 04:46
  46. sorry for the late answer. in lastfm.css file there are the individual styling definitions for :

    #lastfm_recent li .lastfm_recent_date
    #lastfm_recent li .lastfm_recent_artist
    #lastfm_recent li .lastfm_recent_title

    inside of each one you can put:

    padding:20px; (or the value that fits to your design well)

    Posted by Taha Paksu | Monday, July 4, 2011, 20:58


Leave a Reply