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!

7 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.

  • Comment by Webbando
    Date: April 12th, 2010 at 10:51 am

    Hi Sam. Thanks for your post, really useful. But I would have another thing:
    I want change permalink of attachment file from

    http://site.ext/postname/postname-post_id.html/attachment-name

    to

    http://site.ext/photos/attachment-name

    Is it possible?

    Thanks a lot for your support

  • Comment by William Lindley
    Date: March 2nd, 2011 at 1:43 am

    You might also try the AutoNav plugin, which will automatically generate thumbnails and links to child pages, to posts in a category or by slug or author, or by page/post ID:

    http://wordpress.org/extend/plugins/autonav/

Leave a Comment

Image mouseovers without javascript - CSS & Sprites

Date: 3rd March 2008 at 1:27 am | Filed under: development, scripts | Author: Sam Burdge

This article is an extension / improvement upon another article I published on my site previously: {{post id="simple-javascript-for-image-mouseovers" text="Simple Javascript for Image Mouseovers"}}. As I am always looking for improved methods, I was discussing the pitfalls of the javascript method with a friend (and occasional comment writer / contributor to my site) who pointed me in the direction of CSS and image sprites. This lead me to research the topic further, and I found two articles in particular which were incredibly useful:

Read on…

5 Responses to “Image mouseovers without javascript - CSS & Sprites”

  • Comment by Jonn
    Date: April 29th, 2008 at 1:15 pm

    Very nice article. Thanks.

  • Comment by hot girls publisher
    Date: July 13th, 2008 at 7:20 am

    I used this article in the making of this website! Thanks! http://www.girlsbeinghot.com

  • Comment by Ray
    Date: February 18th, 2009 at 4:36 pm

    Super-informative site! I am loving it!! Will come back again - taking you feeds also, Thanks.

  • Comment by Иван Евсеев
    Date: June 13th, 2009 at 4:14 am

    Замечательно написано, но как говорится, для полноты информации нужно минимум хотя бы три источника :)

  • Comment by Datsu
    Date: July 31st, 2009 at 8:20 pm

    This was extremely helpful; exactly what I was looking for and simple to implement. Thank you!

Leave a Comment

WordPress - Change Default Email Address Plugin

Date: 20th February 2008 at 12:04 am | Filed under: development, plugins, wordpress | Author: Sam Burdge

This WordPress plugin changes the default email address that all notifications sent from your blog are addressed from. The default address for all emails sent by your blog is currently wordpress@ yoursite.com.

I had seen some tutorials / forum entries previously where people suggested editing the core WordPress file 'pluggable.php' to overide this default. This method does work, however you would have to repeat the hack every time you upgrade to a new version of WordPress so it is not an ideal solution.

Faced with this problem for a site I was working on recently, I wrote this basic plugin which allows you to configure your own email address in the format: Your Name <yourname@yoursite.com>.

Installation:

  1. Upload the file wp_change_default_email.php to your wp-content/plugins folder
  2. Activate the plugin from the Plugins page in WordPress

Usage:

  1. In the Plugins page in WordPress click the edit button next to the plugin in the list.
  2. Scroll down until you see a note saying 'Configure it'
  3. Enter your name and email as shown
  4. If you don't enter a new address the default 'wordpress@' will remain

Download:


40 Responses to “WordPress - Change Default Email Address Plugin”

  • Comment by Shane
    Date: February 29th, 2008 at 8:33 am

    Works great - thank you!

  • Comment by Change Default Email Address » Wordpress Plugins
    Date: July 9th, 2008 at 6:56 am

    [...] Version: 0.1 - License: n/a - Author: Sam Burge - Plugin Page - » Download [...]

  • Comment by Shane
    Date: August 25th, 2008 at 10:27 pm

    Is there a newer version than 0.1? I upgraded to WordPress 2.6.1 and the Plugins area is telling me that there is a new version, but the new version links to:
    GALLERY LIGHTBOX PLUGIN
    http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/

    Also, just an FYI, version 0.1 now conflicts with the Subscribe2 plugin.

  • Comment by Greg
    Date: September 17th, 2008 at 8:06 pm

    Very handy little plug-in, works like a charm, thanks.

    I’m experiencing a little weirdness, though. I downloaded it from your site. When I install it, it works fine but I get an alert telling me there’s a new version 1.3 (the code says “Version 0.1″) and the link to get the new version points at http://wordpress.org/extend/plugins/wp-25-gallery-lightbox-plugin/ which is clearly wrong. The “Upgrade automatically” option doesn’t work either, with the error mentioning wp-25-gallery.

    Since it works, the only reason I care is I don’t want the little orange flag over “Plugins” in my dashboard, but seems like something you’d want to know.

  • Comment by huski
    Date: October 23rd, 2008 at 10:19 am

    wordpress 2.5
    not working for me, i made the two changes , name and email to the php file, verified the changes were saved in the php file, but it continues to send wordpress and wordpress@domain

    ????

  • Comment by m1k3y
    Date: February 9th, 2009 at 11:06 pm

    Great Job!
    THX !!!

  • Comment by marco
    Date: February 16th, 2009 at 5:08 am

    Hi

    IS the email address restricted to the domain of the website? OR can any email address be used, say gmail account?

  • Comment by marco
    Date: February 21st, 2009 at 11:50 pm

    Hi

    This appears like it will do the (magik) trick but I have an unusual situation in which the email address my client wants for default does not use the website’s domain name in it. So simply setting the name in front of the @ symbol is not sufficient - and neither is my confidence in editing your php to accomodate it. Could write up a note on how this customization in the php file would go?
    Sorry for the xtra trouble. Really appreciate your efforts with this as you can imagine.

    /marco

  • Comment by Açıklamalı 200 Wordpress Eklentisi (Part2) | Paylaşım Keyfi
    Date: March 1st, 2009 at 7:25 pm

    [...] © Change Default Email Address Wordpress varsayılan e-posta adresini değiştirebilmenizi [...]

  • Comment by Beth
    Date: August 3rd, 2009 at 6:40 pm

    I had no idea this was even an issue. I thought that it would just show up with my email by default. That’s dumb.

  • Comment by WordPress için tam 400 eklenti birsayfada! | PiyanoDegil.org :)
    Date: September 2nd, 2009 at 2:59 pm

    [...] © Change Default Email Address Wordpress varsayılan e-posta adresini değiştirebilmenizi [...]

  • Comment by Marcus Naylor
    Date: September 8th, 2009 at 3:35 pm

    Made the changes in the plugin editor, added my From Name and the from Address, updated changes and nothing happened. Still coming from Wordpress

  • Comment by Açıklamalı 200 Adet Wordpress Eklenti Arşivi 2 | Akgün-Web Ailesi
    Date: September 18th, 2009 at 5:29 pm

    [...] © Change Default Email Address Wordpress varsayılan e-posta adresini değiştirebilmenizi [...]

  • Comment by Como mudar endereço email do Wordpress
    Date: October 30th, 2009 at 10:49 am

    [...] ou pode fazer Download do plugin AQUI [...]

  • Comment by Adam
    Date: November 3rd, 2009 at 5:05 pm

    This is a life saver. We were testing the site and discovered the “wordpress@”. We knew we didn’t want that. Wordpress really need to allow users to change this from the dashboard. But anyway, this works perfectly and I wanted to thank you Sam for sharing your expertise with us.

  • Comment by Harry
    Date: November 6th, 2009 at 10:40 am

    Thanks for the plugin.

  • Comment by Tony
    Date: November 14th, 2009 at 1:27 pm

    Works Great!!!!! Thanks!!!

  • Comment by Rhino
    Date: November 21st, 2009 at 12:36 pm

    Hi,
    Thanks for your great plugin. I were used it in my blog, it run so cool. But i have a problem with my language. I use Vietnamese language and the email appear: [Tranh biếm hỠa Việt Nam] Có thà nh viên mới đăng kí

    Can you help me this problem?
    Thanks!

  • Comment by Wordpress 400 Eklenti « www.hakanersoy.org
    Date: January 2nd, 2010 at 12:53 pm

    [...] © Change Default Email Address Wordpress varsayılan e-posta adresini değiştirebilmenizi [...]

  • Comment by Norguad
    Date: January 8th, 2010 at 7:04 pm

    Hi, I used the plugin, but it turns all non-latin characters into weird characeters (for example: é is é or ř is Å™). Do you know how to solve it?

    Thank you very much.

  • Comment by Heath
    Date: March 9th, 2010 at 2:32 am

    Great
    thanhk you sam

  • Comment by Peter F.
    Date: March 9th, 2010 at 3:53 am

    Awesome plugin, guys! Works like a charm, and solves a problem I was afraid would be very tedious.

  • Comment by sol97one
    Date: March 10th, 2010 at 7:03 am

    Thanks a lot ! Very useful !

  • Comment by Terje
    Date: March 15th, 2010 at 12:51 pm

    Same as the others, i have problem with some signs. I try to write the norwegian letter “ø/ø” (ascii ø), but i cant get it to work

  • Comment by frank
    Date: March 21st, 2010 at 12:08 pm

    Hi there, this is a very helpful plugin, I have the same problems with the charset or something else. After installing the plugin I always receive weird characters in my mails. ÖÄÜ are not transformed properly. Thanks. F

  • Comment by Mike
    Date: April 5th, 2010 at 2:03 pm

    Great, thanks for the plugin…If you all are looking for a less extensible…but easier way to modify the email “From” line in wordpress, it’s on line 352 in pluggable.php. Just change [code]$from_name = ‘WordPress’;[/code] to something like…[code]$from_name = ‘Mike’;[/code]

  • Comment by Joshua
    Date: April 5th, 2010 at 11:52 pm

    I am using WP MU 2.9.2. I have installed the plugin and activated successfully. Yet I dont see any settings to configure !!!??

  • Comment by me2t
    Date: April 18th, 2010 at 2:02 pm

    i love this plug in very much.thanx

  • Comment by bosschan
    Date: May 9th, 2010 at 2:16 pm

    give thanx!

  • Comment by Jim
    Date: May 20th, 2010 at 2:10 pm

    Hey, thanks for this plugin, helped me sort out a really annoying reg problem I had :D

  • Comment by PLnet
    Date: May 25th, 2010 at 3:32 pm

    thank y

  • Comment by Greg
    Date: June 27th, 2010 at 2:25 am

    Great plug-in, just what I was looking for as I didn’t want any emails say “wordpress”

  • Comment by Thiago Dias
    Date: August 12th, 2010 at 3:45 am

    thanx!

  • Comment by TomCap
    Date: September 6th, 2010 at 1:56 am

    Worked like a charm. Another little irritating item solved. Thanks!

  • Comment by Maira
    Date: January 21st, 2011 at 12:59 am

    worked. highly recommend. thank you!

  • Comment by oriflon
    Date: February 17th, 2011 at 11:49 pm

    how to edit manual?

  • Comment by SteveB
    Date: February 18th, 2011 at 12:20 am

    I loaded the plug in but can’t find it in the plugin list.

  • Comment by haohuu_lam_em
    Date: March 3rd, 2011 at 10:04 am

    Can not convert to UTF-8!

  • Comment by Demo Games
    Date: April 8th, 2011 at 9:20 am

    Thanks for sharing works fine on wordpress 3.1.1

  • Comment by I Shoot Reno
    Date: April 19th, 2011 at 9:23 pm

    Fantastic solution! Minimal effort needed to make this work from a novice’s standpoint!

Leave a Comment

Encoding Flash Video (flv) - Part 1 - The Basics

Date: 16th February 2008 at 12:53 am | Filed under: development, flash | Author: Sam Burdge

This is the first part in a series of articles I will be writing on encoding Flash Video (flv files) using the Adobe CS3 Video Encoder. I intend to cover all aspects of flv encoding to help you to attain the best results possible. If you are using another software to encode your flv files, such as Adobe After Effects or Final Cut Pro, many of the principles will be the same.

Read on…

4 Responses to “Encoding Flash Video (flv) - Part 1 - The Basics”

  • Comment by Grant Forrest
    Date: February 29th, 2008 at 10:29 am

    Hi Sam Been hunting the internet for some advice on optimum source files for flash - with no joy. But came across your encoding flash video article and have been enlightened. Many thanks Grant

  • Comment by John Smith
    Date: July 8th, 2008 at 2:50 pm

    Very helpful information. Much appreciated. Thank you.

  • Comment by samir
    Date: July 15th, 2008 at 6:03 pm

    Thank you for this useful article.
    Very informative.
    It solved my issue with horizontal lines in flash video files.

  • Comment by Addict
    Date: April 20th, 2009 at 2:22 pm

    Thanks, Good stuff. Found the solution to the horizontal line issue here too.

Leave a Comment

WP Custom Title Colour Plugin

Date: 31st October 2007 at 8:42 pm | Filed under: development, plugins, wordpress | Author: Sam Burdge

This WordPress plugin does exactly what its title suggests, gives you the ability to customise the title colour for any post via a panel in the sidebar of the write page. Handy for creating alerts, or drawing attention to a particular post.

Instructions:

  1. Download the plugin file here: WP Custom Title Colour Plugin
  2. Upload the folder 'custom_title_colour ' into your 'wp-content/plugins' folder
  3. Activate the plugin via your plugins page in wordpress
  4. When writing or editing a post you can control the title colour via the 'Title Colour' tab in the right sidebar.

This plugin utilises the Colour Picker Selector script by: FREE-COLOR-PICKER.COM

17 Responses to “WP Custom Title Colour Plugin

  • Comment by Lafdil
    Date: November 2nd, 2007 at 10:23 am

    does this script allow to change also the font & the size ?

    thank you

  • Comment by Sam Burdge
    Date: November 2nd, 2007 at 1:31 pm

    Hi, it only changes the colour at the moment, but I could easily add those features for a future version, good suggestion! I have just released the plugin, to see how people respond to it, so it may not be updated for a while. However, I will email you and let you know when the next version is released.

  • Comment by Zachary Guidry
    Date: November 2nd, 2007 at 4:51 pm

    Thanks for the plugin! I have a minor comment - when I unzipped the file, it did not create a folder called ‘custom_title_colour’. You may want to create the zip so that the extracted files are in the properly named folder.

    Again, thanks for sharing - I have many ideas on how to use this plugin.

  • Comment by Zachary Guidry
    Date: November 2nd, 2007 at 5:00 pm

    I just installed the plugin and it works wonderfully. I noticed that you used the same color picker I used in my Multiblix plugin. You can view Multiblix at http://blog.websitemechanics.com/?page_id=3

    Zack

  • Comment by Sam Burdge
    Date: November 2nd, 2007 at 5:41 pm

    Thanks for the feedback, I’ll change the archive so that it contains the correctly named folder inside it. Multiblix looks very cool!!

  • Comment by Thunder-man
    Date: March 24th, 2008 at 3:56 pm

    Hy, I become this Title
    Age of Japan”>Age of Japan
    My Theme is WP-Andreas09

    Thunder-man

  • Comment by zulu
    Date: June 14th, 2008 at 12:40 pm

    Hi. Nice idea :) but doesn’t work with my blog. Like Thunder-man, I always get two titles, first one in black (standard) with “>, second one is in customized colour, like:
    Message in a bottle”>Message in a bottle

    It`s also impossible to reset given colour back to “none”, last chosen colour seems fixed.
    My theme is Silver Shine 1.0 by IS.

    zulu

  • Comment by mutantz
    Date: July 15th, 2008 at 12:15 pm

    Hi! Cool plugin, but i need choose background color and border-bottom ) Can u fix this for me?))))
    sorry for english)

  • Comment by peweck
    Date: July 15th, 2008 at 8:12 pm

    doesn’t work with my blog. Like Thunder-man ans Zulu…

  • Comment by GamA
    Date: August 29th, 2008 at 2:05 am

    can you add a background color change feature as well?
    its what i was really looking for.

  • Comment by GamA
    Date: August 29th, 2008 at 2:08 am

    i was talking about the post title background. also this plugin does not work for me same as Thunder-man and Zulu.

  • Comment by Czymra
    Date: November 5th, 2008 at 1:43 pm

    When using this plugin, make sure you use ‘get_the_content’ instead of ‘the_content’ in your theme, then it will work.

  • Comment by Wordpress themes and plugins for the week 7 | aw-aw.com
    Date: January 21st, 2009 at 5:11 pm

    [...] WP - Custom Title Colour plugin This plugin gives you the ability to customise the title colour for any post via a panel in the sidebar of the write page. Handy for creating alerts, or drawing attention to a particular post. It’s easy to install and works like a breeze. [...]

  • Comment by WordPress 插件集锦系列 1-50套 « wordpress 非官方中文站——助力中文wordpress
    Date: May 2nd, 2009 at 2:47 am

    [...] WP Custom Title Colour 让你可以在写文章的时候,通过侧边拦的面板来定义标题的颜色。 [...]

  • Comment by Custom Title Colour | Eklenti.net > Wordpress Eklentileri
    Date: August 31st, 2009 at 10:27 am

    [...] Eklenti Ana Sayfası [...]

  • Comment by david
    Date: November 3rd, 2009 at 4:33 pm

    Good, but would be cool if I could drag it to the side bar so I didn;t have to scroll to the bottom of the page to use it. Also when I click to select colour, the colour picker appears right back up at the top of the page. A bit clunky but did the job and I’m looking forward to updates!

  • Comment by ymel
    Date: May 4th, 2011 at 6:00 pm

    tks, it would be nice, but some code can be seen on the screen in the beginning of the post after using it

Leave a Comment