Issue 4 will be out some time in the future. WP Mag is on holiday while its writer is busy after moving house!
Home » Issue 3

Use last.fm to play music in your sidebar

5 November 2008 2,275 views 12 Comments
Use last.fm to play music in your sidebar

By creating a library of your favourite artists at last.fm you can share your music with your blog readers.

There are several MP3 player plugins available, but by using last.fm’s player you will be completely legal and will avoid using loads of your bandwidth by streaming the tracks yourself!

You can choose from a few different colours - so it will match your site - along with other display options.  Whenever you add more artists to your last.fm library they will be instantly available on your blog’s playlist.

1. Sign up to last.fm and add artists to your library

Sign up to last.fm if you aren’t already a member.  You can search for your favourite artists and add them to your library using the blue button show in the screenshot below.  You can add artists at any time without needing to modify your widget, so just add a few for now to get you started.

2. Create a player widget on last.fm

Once you’ve added some artists go to www.last.fm/widgets to create a player widget.  On my own site I’m using a “radio player” to play random tracks chosen from my entire library.  “Quilts” shows ever-changing images of album covers from yoru library, which looks fun!  The other option available to WordPress users is “charts”: this will only play tracks you have recently played on last.fm.

You can also select the colour and size of your widget.  When you’re happy with it press “Show me the code” and copy the code it gives you onto the clipboard, ready to add it to WordPress.

The final step will vary depending on whether or not your theme uses WordPress widgets.  If your theme supports widgets you can do step 3a.  If your theme doesn’t support widgets, or if you choose not to use them, do step 3b.  Note that as soon as you add a single widget in Design > Widgets it will replace your whole default sidebar in most themes, so you will need to add other widgets alongside your new widget.

3a. Using the widget if your theme is widget-enabled

If your theme supports widgets, and you choose to use them, adding the last.fm player is easy.  Go to Design > Widgets in WordPress Site Admin.  At or near the bottom of the unused widgets on the left you will see you can add a “Text” widget.  After pressing “Add” it will appear on the list on the right.  Press “Edit” on this new widget.

There is space for an optional title at the top and a space for you to paste in the code from step 2.

Once you’ve done that, press “Change” to save the text widget, then “Save changes” to make your new widget appear on your site.  Take a look at your site, press play and turn up the volume!

3b. Using the widget if your theme doesn’t use WordPress widgets

If your theme doesn’t use widgets, or if you just prefer not to use them, you’ll need to edit your theme’s sidebar template.  You can find this at wp-content/themes/your-theme-name/sidebar.php.  If you want a guide to editing theme files read Making a theme series (part 1).  I’m going to add my last.fm player under the tag cloud, but you can add it wherever you like.  Find the place you want to put it and paste in the code from step 2.  Lines 11 and 12 below represent the pasted code, but I haven’t included it all here because it’s huge!


<div id="sidebar">
    <ul id="navigation">
        <li><a href="<?php bloginfo('url'); ?>" Title="Home">Home<a></li>
        <li><a href="<?php bloginfo('url'); ?>/tag/photos" Title="Gallery">Gallery<a></li>
        <?php wp_list_pages('depth=1&title_li='); ?>
    </ul>
    <div class="wp-tag-cloud">
        <h2>Tag cloud</h2>
        <?php wp_tag_cloud('smallest=0.8&largest=1.8&unit=em'); ?>
    </div>
    <style type="text/css"> (huge block of code from last.fm goes here)
    <table (another huge block of code from last.fm goes here)
</div>

Upload your changed sidebar.php if you need to, then take a look at your site.  You and your visitors can now enjoy music from your favourite artists!

Top image copyright last.fm.
Email this article
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

12 Comments »

  • N said:

    I prefer to use a playlist from Favtape.

  • Piscianemperor said:

    Hello…i’m using the Jentri theme for my wordpress blog. Apparently,when i copy the code into the text widget,the whole code itself is shown on the blog.I’m pretty sure i’m following the right procedure.Is there any solution to this ? i read somewhere that wordpress.com doesn’t support third party applications. please help.

  • Steve Smith (author) said:

    I’m afraid that’s right, the text widget is only for plain writing, not code. I can’t think how you can put the player in your sidebar on WordPress.com. However you could try putting it on a page. Make a new static page, perhaps called “Music”. Edit that page and click HTML View. Try pasting the player code in there.

  • Piscianemperor said:

    No…even that didn’t help.When i paste in html,again the whole code shows ! Anyways,thanks a lot for helping. I’ll put a rss link instead.

  • Steve Smith (author) said:

    Above the text-entry box, where it says “Visual” and “HTML” did you make sure you pressed “HTML”?

  • Chris Gibbons said:

    This just isn’t working. Where is this “Visual” or “HTML” option? It’s not showing up on my dashboard.

  • Steve Smith (author) said:

    I just tried putting Last.fm on my WordPress.com blog, and found that it won’t work. WordPress.com doesn’t support JavaScript. You’ll need a self-hosted WordPress to use this tutorial! Sorry, it hadn’t occured to me before.

  • Si said:

    Any idea how you can stop the player reloading whilst moving from post to post?

  • Steve Smith (author) said:

    The only simple way I can think is using an IFrame in your sidebar. Link the IFrame to lastfm.html or something like that, then put the Last.fm player code in that file.

  • Matt said:

    Thanks, worked for me! I’m on my own hosting, though.

  • Steve Smith (author) said:

    No worries!

  • Sergiu said:

    When I’m trying to access http://www.last.fm/widgets - it turns automatically to http://www.last.fm/tools/charts - and can’t create my own player. Can anybody help me with that? Thank you!

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

You can get your own avatar which will appear here and on other Gravater-enabled sites.