WordPress attachments hack

Date: 9th June 2009 at 3:19 pm | Filed under: blog, development, scripts, wordpress | Author: Sam Burdge | Tags: , , , , , ,

While working on a WordPress site recently I came up against a problem that had never occurred to me before. The client wanted each post excerpt on the homepage to include an image which when clicked would link to the main post (permalink) itself. The built in functions of wordpress when inserting an image allow you to link to either the 'File URL' (i.e. the full size version of the image) or to the 'Post URL' which is actually an attachment page in wordpress which displays the image, but does not include the text of the actual post itself. However, without either editing the html of each post (not an option for this client) or inserting the image without a link, and then adding the permalink to the image (too long winded) there was no simple way to create the image links in the way they wanted them.

My solution to this was to create a very basic hack which would allow them to use the 'Post URL' link when inserting images, but instead of linking to the attachment page, the link would automatically be updated to link to the post's permalink itself.

Here is the basic php function that you would need to insert into your theme's functions.php file:

function lose_attachment($content){
return preg_replace('/<a(.*?)href="(.*?)\/attachment\/(.*?)"/i', '<a$1href="$2"', $content);
}

add_filter('the_excerpt', 'lose_attachment',2);

This will remove the 'attachment/name-of-image-file' part from the URL making it link to the post's permalink itself.  I hope someone out there finds this useful!

5 Responses to “WordPress attachments hack”

  • Comment by akshay
    Date: June 14th, 2009 at 3:27 pm

    really good post….tutorial is very helpful for me …thanks a lot for giving out such good tutorials

  • Comment by Alex Holsgrove
    Date: June 29th, 2009 at 8:54 am

    This was a great help. Thanks for sharing the code

  • Comment by Abeon
    Date: July 13th, 2009 at 10:26 pm

    This is a great little hack :)
    Simple but effective!

  • Comment by Nate
    Date: August 12th, 2009 at 1:21 pm

    I can’t wait to try this out.

  • Comment by Betaclick SEO Company
    Date: September 17th, 2009 at 7:32 pm

    Thanks for the code dude, i need to try this out on my wordpress blog! As im learning advanced use of it.

Leave a Comment

The Transfer Tavern

Date: 9th June 2009 at 2:37 pm | Filed under: portfolio | Author: Sam Burdge

untitled-1untitled-2untitled-3untitled-4

The Transfer Tavern is a pub themed blog / site about football transfer rumours. It features two different voting systems by which readers can vote on the pluasability of each rumour, deciding whether the rumour should 'Fly or Die' and also a beer rating to decide how drunk you would have to be to believe the more outlandish rumours.

The most interesting and challenging aspect of building the site was designing and implimenting the custom voting systems. I also designed the pub style logo for the site which I am quite pleased with! If you like to keep up to date with all the latest footy rumours, or want to find out what purchases your team might be making over the summer transfer window then be sure to check it out: www.footballtransfertavern.com

Leave a Comment

Branded Quiz Games

Date: 9th June 2009 at 12:23 pm | Filed under: flash, portfolio | Author: Sam Burdge | Tags: , , , ,

I have developed a quiz game engine based on this original multi choice quiz by animike. The improvements I made to the original flash file are:

  1. Removed the need for an external XML file, which makes it easier to distribute virally as a stand-alone file.
  2. Added the ability to add infinite arrays of questions, so the quiz will have a different set of questions each time you play.
  3. Added the potential to build arrays of questions based on statistical data, perfect for sports quizes.
  4. Added the potential to plug the game into various scoreboard and in-game advertising APIs such as MochiAds.
  5. Added brandable features such as a 'More Games' link and a preloader screen.

To test the quiz engine I released the first version of my football quiz, with 12 questions drawing from an array of 120 possible questions. It got mixed reviews on newgrounds.com, but seemed to do reasonably well on football / sports specific games sites thereafter. You can try out the first version of the quiz game here: Football Quiz

More recently I have released the first sponsored / branded version of the quiz called Premiership Football Quiz, which is sponsored by one of the UK's leading football websites - FootballFanCast.com. I have plans to work with the FootballFanCast team to develop other football quiz games, relating to specific teams, competitions, etc.

I am also hoping to branch out now into quizes relating to other sports, and to other subjects entirely, such as Pop Music, Movies, TV, Celebrities, Arcade games, World Geography, etc.

If you need a quiz game for your site, or wish to distribute a branded quiz game across a range of games sites please feel free to get in touch. I can quote on a per quiz basis, prices will depend on the level of branding, the number of questions, whether the questions are provided, whether you want me to distribute, etc. So there is no fixed price as such.

1 Response to “Branded Quiz Games”

  • Comment by Jimmy
    Date: September 19th, 2009 at 8:06 pm

    I use latest wordpress what do I do wrong? I get each column one row lower, whatever I do it still does this. Is it a bug with newest Wordpress? Ive followed everything step by step.

Leave a Comment

Widgetbox widgets

Date: 25th May 2009 at 1:49 am | Filed under: blog | Author: Sam Burdge

I have just created these two widgets for my plugins feed and Zap Gamez over at Widgetbox. This is the most basic type of widget called a Blidget. Widgets are cool, I will definitely make more!

Leave a Comment

Corporate Flash Animated Banner

Date: 23rd May 2009 at 12:13 pm | Filed under: flash, portfolio | Author: Sam Burdge | Tags: , , ,

Working with design agency Pollen London, I developed this simple, eyecatching flash banner for client Project Associates' website home page.

pollen-screen

The banner shows a constantly moving, rotating array of their team, each image linking to the specific person's profile on the site.

Check out their home page to see the banner in action:

www.projectassociatesltd.com

Leave a Comment