Ad for Tradeomics

Add a Custom URL to your WordPress Gallery Images

Now a WordPress plugin on Github: https://github.com/brewern/gallery-custom-link - This post has been updated now that the code is on Github.

By default each of your gallery images either have no link, file URL, or post URL. You can see this by viewing the images you have attached to your page. What if you wanted a custom link for each image in your gallery. This would be helpful if you wanted a gallery image to have an outbound link or link to a page on your site.

I read a few blog posts looking for this solution, one or two steered me in the right direction. Forgive me for not linking to those sources as I cannot remember how I found them.

After you have installed this plugin, upload a few images and add a gallery to your page. Edit that gallery and you can see the new text field we have added. Here is a before and after:

Before

After

One last change to get the gallery to start showing your new custom link. Go to the HTML tab of the WordPress Wysiwyg and change the gallery shortcode link attribute to “custom”. IMPORTANT: the previous version of this plugin used the link value of “custom_url”, this has changed!

Change Gallery Shortcode

Important Note: Keep in mind that this plugin uses and overrides the core gallery function. Future WordPress versions could break this plugin, although it has lived through several. I’ll try to fix this plugin as soon as possible if it does break from an update. Leave a comment here or on Github in the event that it does break.

Enjoy.

Be Sociable, Share!

  • Tony

    Great idea…this is exactly what I and many others are looking for, however where do I put the “add_filter” lines? Clearly, these do not go into functions.php

  • http://www.nick-brewer.com Brewern

    @Tony: Yes you put the “add_filter” lines in the functions.php file. All of the code above goes into your functions.php file.

  • Dustin

    Have you thought about making this a plugin? Also, everything appears to be working correctly for me except the last step. When I add link=”custom_url” to the shortcode I am getting the image attachment page (default) link. Any ideas? Thanks!

  • http://www.nick-brewer.com Brewern

    @Dustin Sorry about that and thanks for the catch. I forgot the add_shortcode function. The code has been updated.

  • Dustin

    Awesome – works great!

  • http://www.demo38.com Jonathon

    Thank you for this. By tweaking your second block of code here with the code hack I found here: http://blog.mattsatorius.com/technology/web-design/wordpress-gallery-shortcode-with-no-image-link/ I was able to then use link=”none” inside of the WP gallery shortcode to disable the links. Great stuff!

  • http://www.nick-brewer.com Brewern

    @Jonathon Great! Glad the post helped.

  • Eee

    this isn’t working for me. I pasted all of the above code in my functions.php file (within theme folders) and the custom link field displays in the image uploader window. But after adding [gallery link="custom_url"] thumbnails are still automatically linking to an attachment page….help please?

  • Eee

    NVM. I solved my own problem. Like an idiot I didn’t paste the code at the end of the file. I moved it to the bottom and it worked. THANKS SO MUCH!

  • http://nick-brewer.com Nick

    Glad it’s working for you.

  • Claudio Pascual

    Hello,
    your code was very useful for me, I used it as an inspiration for inserting a new field in the gallery detail for displaying and updating the slug (post_name).
    Cheers,

    Claudio

  • http://twitter.com/losetheflame Trista

    oh man.. I wish this worked with the polaroid plugin… but it didn’t. none the less, worked like a charm for the gallery. thank you!

  • Kate

    RAD!! I’d been searching for this exact thing. Thank you!! Took me a while to figure out I could just skip the second bit of code and just use:

    get_post_meta($id, ‘_rt-image-link’, true);

    as a variable in the plugin I’m modifying to pull from the custom URL. Thank you!!

  • Coatonasuanasua

    Works perfectly with WordPress 3.1! Many Thanks!!

  • Marco

    Is it possible to add the image right to the gallery?

  • http://nick-brewer.com Nick

    I’m not sure what you are asking. Could you be more specific?

  • Jehnuine

    Ok this is not working for me… what am I doing wrong? I copied the first code into the functions.php file and then I got a gnarly error. then I tried entering the second code below the first code in the functions.php and still got a gnarly error… please help.

  • http://nick-brewer.com Nick

    At the very least the first bit of code should not be giving an error. What version of WordPress are you running? This has only been tested for WP 3.0+. Double check to make sure all the code was copied and you’re not missing any closing semicolons.

  • Sebastian

    Thank You for the recipe, it really helps me re shopping cart theme.

  • Urquhart4

    This didn’t work for me. I copied the two post into my functions.php file. Then, it was showing text all over my wordpress dashboard. I signed out of the dashboard, went to the website and the code was showing up there.

    What am I doing wrong? BTW, i’m using WP 3.1.

  • http://nick-brewer.com Nick

    Could you send me a link to your site to see the error or link to a screenshot?

    If the code (php) is showing up on your website then you may have not pasted the above code within a tag.

  • Urquhart4

    thxs for the speedy reply. you were correct, i didn’t paste the code within the tag. Now that I’m seeing everything you have in the pics above. But I have another problem, when i click on the picture, it isn’t linking to the external page.

  • http://nick-brewer.com Nick

    Did you change the shortcode link to “custom_url”?

  • Urquhart4

    Yes, I added the [gallery link="custom_url" columns="2"].

  • http://nick-brewer.com Nick

    Is it linking to the image or to anything at all? Is there a way I can access your WP admin for you and see if I can figure out the issue. You can email me brewer.nick@gmail.com

  • Jehnuine

    My images are coming up as double….

    http://www.jehnglynn.com/

  • http://jehnuinedesigns.tumblr.com/ jehnuinedesigns

    Hi! My images on the homepage are showing up double and not linking anywhere..

    Please help!!
    http://www.jehnglynn.com

    (I thought I posted a comment the other day but I guess it did not go through…)

  • http://nick-brewer.com Nick

    It looks like you may have html in your link url which is breaking it. Or possibly left off some code when copy and pasting the code above. If you would like to email me a login I can take a look – brewer [dot] nick [at] gmail [dot] com

  • Hilmon

    THANK YOU SOOOOO MUCH!!!! This is exactly what I was looking for…. Works like a treat!!!! Now I just need to turn the gallery into a carousel… ha ha ha!!!! :-/

  • Sebastian

    Are you the developer.
    What theme are you using. Modest theme.
    Have you changed any of the templates, maybe the Page of page-loop template.
    Put site in maintenance.
    Use editor.
    Change the page.php and page-loop.php name to back up.
    Copy the page.php template and then the Page loop template from “computer to site directory where applicable.
    See what happens. If something is goes wonky you have the original files.
    That’s what I would try.
    I use twenty-ten. Once you get to know it is amazingly flexible. I assume modest has something like page.php

    Even better idea in appearance themes change to twenty ten theme and see if the images still double up.

  • http://wpgarage.com Rebecca

    Um… you are my hero! Thank you. It’s so ridiculous that this isn’t built in and that you have to do such a crazy workaround.

  • http://nick-brewer.com Nick

    You’re welcome. And I completely agree.

  • Jim

    I get Fatal error: Call to undefined function add_filter() in …./wp/wp-includes/functions.php on line 4501, which is part of the Custom Link :

    add_filter(“attachment_fields_to_edit”, “rt_image_attachment_fields_to_edit”, null, 2);

    I’m using a Graph Paper Press theme so I’ve no idea if they’ve modified functions.php so this wouldn’t work, but they did suggest trying your solution.

  • Tom

    help me! I tried this and now just get this error:

    Fatal error: Cannot redeclare gallery_shortcode() (previously declared in /home

    I can use my blog now can anyone help? I am sure its just me being stupid!!!

  • Tom

    fixed it!

    would still love to get this to work but ill settle with having my old site back!

  • Garry

    Hi Tom,

    I’m no expert, but of you can’t access you probably messed something in functions.php. To have your blog working back, simply replace the current functions.php with the original one of your theme. (do it throug ftp)

  • Warwick

    Hi, I had the same problem! It happened after I deleted an image from the gallery. After a lot of faffing I found that in HTML wysiwyg editor the “custom_url” entry had reverted to “file”. Change it back and it should work. If that doesn’t work try removing all the gallery images from the media library (last tab on the gallery editor) and re-uploading them. Then make sure that the “custom_url” bit is still there- it worked for me!

  • http://nick-brewer.com Nick

    I believe it may be that the shortcode “gallery” is already being modified in your theme, causing a conflict. Trying changing “add_shortcode(‘gallery’, ‘geekee_gallery_shortcode’);” to “add_shortcode(‘custom_gallery’, ‘geekee_gallery_shortcode’);” – then use [custom_gallery] as the short code in your post/page, don’t forget the other attributes in your shortcode.

    I will be rewriting all of the above code soon. I plan to filter the gallery to make my changes rather than just rewrite the whole function.

  • http://nick-brewer.com Nick

    That is odd. What version of WordPress are you running?

  • http://nick-brewer.com Nick

    Did you get this worked out? I tried accessing your site but it was down at the time.

  • Garry

    Hi,

    apparently I didnt go through the whole comment process. Thank you very much for this hack, but I got a problem. After following every step you give, my ulrs look like this : http://www.mydomain.com/www.thedomainIwanttolinkto.com.

    How can I fix that please?

  • http://nick-brewer.com Nick

    Sorry, Disqus requires the comment to be approved if it includes a link.

    The problem you are having is most likely caused from not having “http://” included in your link.

  • Irfan_bahalwan

    It doesn’t work!
    I’ve added the 1st code into functions.php, the 2nd code into media.php.
    And first of ll change the > into > , &amp into &.
    Then when I refreshed my back end, it shows error.

    It couldn’t execute the add_filter() functions

    I’ve commented the add_filter() functions, just to try it out, and it still has errors in media.php file

    FYI, I’, using WP 3.1.1.

    If you dont mind, could u post the modified functions.php & media.php that works in WP 3.1.1 here?

  • http://nick-brewer.com Nick

    All of the above code “as is” needs to go into your functions.php file, not the media.php file. There shouldn’t be any issues with WP 3.1.1.

  • Kermit Woodall

    I’m having quite a few problems with the code … it seems that many => and -> and && have been transcoded into =$gt; and -> and && and the like.

    Is there a download of this code, unaltered, that I could use?

    Kermit Woodall

  • http://nick-brewer.com Nick

    I added a pastebin link to the post. http://pastebin.com/smfPfwgW

    Sorry for the delayed comment or response to your email. We have been dodging tornadoes here in Arkansas.

  • Kermit Woodall

    Keep dodgin’! Thanks for the Pastebin but there’s still some transcoded problems and some double quotes where a single quote (or vice versa) should have been. You’ll see some && in some areas and at the top there’s an unnecessary <?php as well. I tried correcting it all but ended up with this, not quite right, Gallery page. http://www.morsepi.com/most-wanted/

    Thanks for the help!

  • Kermit Woodall

    Stupid DISQUS filter. I was saying there was an unnecessary < ? PHP at the top. Not an unnecessary Thanks for the help. :)

    Kermit Woodall

  • http://nick-brewer.com Nick

    Sorry about that. Check the link now, all of it should be cleaned up.

  • Kermit Woodall

    Still having problems – I think this line is wrong – might be others. Thanks!

    1
    $output .= "<a href="$link">$image</a>";

    Kermit Woodall

  • http://nick-brewer.com Nick

    Updated. Haven’t had a chance to test these minor fixes.

  • Alan

    Where do I have do insert the code insede functions.php ?? I copy and paste both codes but it doesnt work It makes the site stop working and i have to replace the functions.php file by the original via ftp.

  • Alan

    I have solverd this problem, but now i have another one. The gallery had 3 columns, but now it has only 1 and i cant make it have 3 columns again. What can i do?

  • Alwin

    Please, let me know where to paste the code in funcions.php

  • http://nick-brewer.com Nick

    Anywhere. I usually just paste it at the bottom.

  • Alan

    I have found a plugin that solve this problem, its the Gallery Just Better plugin

    You dont need to mess with the code anymore, just install the plugin and type the url link on the description of the images from the gallery. Then change the view to html and change the shortcode of the gallery to this one:

    [galleryjb link="url"]

  • http://nick-brewer.com Nick

    Awesome.

    Although keep in mind that you will be locked in to this plugin on your site, not sure how many pages/posts you will have or for how long. If support for the plugin stops it may be a lot of work to change over to something like what I have written above. The reason for not making my own shortcode is so that at anytime you can stop using the above code and have a regular gallery.

  • Chris

     I’m getting this error: Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in /hermes/bosweb/web066/b661/ipg.echolynfannet/wp-content/themes/twentyten/functions.php on line 515

    Any ideas on what I’m doing wrong? I did paste the code at the bottom below the original function.php code using the http://pastebin.com/smfPfwgW

    Any help would be appreciated…thanks!

    Chris

  • http://twitter.com/rima_gerhard Rima Gerhard

    The problem with the code is that the icontag and itemtags weren’t being closed properly, here is the fix

    /* ——————————-
      MODIFICATION ################
      ——————————- */
      $image = wp_get_attachment_image($id, $size, false);
      $attachment_meta = get_post_meta($id, ‘_rt-image-link’, true);
      if($attachment_meta){
        if($attr['link'] == ‘custom_url’){
          $link = $attachment_meta;
        }
      }

      $output .= “”;
      $output .= “”;

      /* ——————————-
      MODIFICATION ################
      ——————————- */
      if($attachment_meta){
        $output .= “$image“;
      } else {
        $output .= $link;
      }

      $output .= “”;
      if ( $captiontag && trim($attachment->post_excerpt) ) {
        $output .= “” . wptexturize($attachment->post_excerpt) . “”;
      }
      $output .= “”;

  • FreedomTech

    Did anyone find the fix to the one column problem?  I have it too.  I have
    [gallery link="custom_url" columns="3"]
    but it still only give one column.

  • Urbn

    Fantastic code! did just want I needed.

    For those having problems with the error messages in the functions.php page the fix is easy.

    Most likely you are editing the wp-includes/functions.php (which is what I did at first).  You do not want to edit this file!

    Where you need to place this code  is the functions.php file inside your THEME.  You can edit (or create if it does not exist) wordpress-install/wp-content/themes/theme-name/functions.php

  • David Abbott

    In the last modification change the end of the line that begins

    $output .= “”

    from

    ‘;

    to 

    ”;

  • Jeff

    Yeah, I still can’t get the columns to work. Same issue as FreedomTech, with or without the code fix David Abbott proposed.

  • http://nick-brewer.com Nick

    Sorry you are having issues with this Jeff. I’ve been a bit busy lately, I will take a look at the issue and provide a solution in the next couple of days.

  • Jeff

    Appreciate it Nick. It’s so close to being perfect!

  • http://www.facebook.com/brianfrolo Brian Frolo

    I just solved the columns thing. Will post after dinner.

  • http://www.facebook.com/brianfrolo Brian Frolo

    I compared the page source for a standard gallery to the that created by Nick’s code. Certain tags were not closing. This http://pastebin.com/y96aDAnd does that. Thanks for creating a piece of awesomeness!

  • http://www.facebook.com/brianfrolo Brian Frolo

    And you need this too: http://pastebin.com/SWu3Q1QB

  • http://nick-brewer.com Nick

    Thanks Brian for modifying the code. I have updated the pastebin in the blog post with the revisions you have added.

  • Elizabeth229

    Hi – I’m having a little difficulty pasting the code in! I got a parse error that required me to re-upload functions.php via FTP (as someone else had mentioned they’d had to do).  Where specifically do the pieces of code get pasted?  I’m very much a newbie so help would be appreciated :)

  • http://nick-brewer.com Nick

    Copy the code from the link at the top of this article and paste into your functions.php file in your theme folder. The preview of code in the Article is converting “>” to “>”, looking at an alternative to display code.

  • Ally Reeves

    Truly Bummed. Tried to add this code and my whole WP site has crashed with a syntax error.  Was using 3.1 and have no clue what went wrong. Could you note *where* in functions.php this code should be placed? Top or bottom…

    Also unclear on 2nd bit of code. Are we taking anything out of media.php or are you just telling us you took something form there? This code post seems simple enough but alas it’s sunk my WP ship so please add some more detailed descriptions on how to make this add.

    thnx!

  • http://www.bluegrassinternet.com Chaley

    Awesome! Helped me out in a pinch!

  • Andy

    this is so close to working perfectly! pasted at the end of functions.php -  but there seems to be some kind of parse error – it shows two images and a closing ‘> – seems like a really simple fix, but i can’t work it out….

  • Andy

    on wordpress 3.2.1 – maybe that is the problem?

  • Silverfh

    simply super… I just used ths code to understand gallery function.. and now em doing my own gallery plugin…
    thanks a lot… 

  • Carolineniland

    Hi there,
    I’m using your code (taken) from the link above and pasted into my functions.php file.  I’m using WordPress 3.2.1 and I’m getting a double thumbnail of the image that I add the custom link too.  When I click one of the images it doesn’t go to the URL that I added into the custom field but has the following ending in the url <a%20href=   

    Can you help?  All the best, Caroline

  • chinny

    same issue as andy and carolineniland. double image and the url is broken. using WP 3.2.1

  • Muhammad Ashfaq

    how can i get custom link in my site ? it is working in admin panel…

  • chinny

    for anyone having the > issue. something to try: i went through my wp database and checked for rogue file paths. (i had moved servers and change the uploads directory in the settings). i also found that I was having the > issue on one image only. The rest were ok. I deleted that image and re-uploaded it with a new file name. everything is happy now.

  • http://nick-brewer.com Nick

    Sorry to hear that! Copy the code from the pastebin link at the top. Be sure you don’t copy “<?php" into your functions.php file if it is already at the top (most likely the case).

    Take nothing from media.php, that is just where I pulled the function from. All the code you need is found above.

  • http://nick-brewer.com Nick

    Sorry I am just getting back to you. Did you ever get this resolved? I’ve tested this in the latest version of WordPress with no issues. Be sure to copy the code from the pastebin link at the very top of this article.

  • http://nick-brewer.com Nick

    You are very welcome!

  • http://nick-brewer.com Nick

    Are you using the shortcode shown in the last thumbnail image? Not having “custom_url” as the link value in the shortcode can cause this.

  • http://nick-brewer.com Nick

    Thanks chinny for posting this solution. That is odd, not sure what would cause the image to be breaking things.

  • Jon

    I’m having the same problem, I wanted an image to link to a youtube video.

    I tried putting those two chunks of data at the bottom of the functions.php just above the closing ?> but I get an error when doing that

    Where and how exactly should I be adding it into the functions.php file?

  • Jon

    I see there are both a core and a theme functions.php. I tried adding to both, got the same error on the same line both times.

    “input” => “text”, // default

    Parse error: syntax error, unexpected ‘=’, expecting ‘)’

  • Jon

    Ah it works if I copy from pastebin.

    However is there anyway to automatically use the custom url if there is one present, rather than having to specify it with a shortcode. I’m using another plugin that automatically has the gallery on the page without using the shortcode and that is still using the original image link, not the custom one in the box.

  • http://nick-brewer.com Nick

    Glad to hear you got it working. I’ve got to figure out an alternative for code sharing in WordPress.

    You could try changing the line “if($attr['link'] == “custom_link”)” where “custom_link” is to the default, which I believe is “file”. So that line would read ”if($attr['link'] == “file”)”.

  • Jon

    Thanks Nick,

    Doing that change does make the thumbnail use the custom url as the link in a gallery on a normal blog post. It doesn’t work with the plugin I’m using but that would be a separate issue. I’ll have to just hope they fix the bug in the next wordpress update. 

    One thing that it doesn’t do though it work with the gallery lightbox as there is no rel=”lightbox” (or whatever rel value you need) on the link tag. I tried adding it to $output .= ”$image“; as that looks like the line which generates the html code but my php know how is limited and I couldn’t get it to work. Adding it in the custom url box just adds it to the hyperlink itself so that didn’t work either. Currently that one thumbnail in the gallery which links to a youtube video takes you to the youtube page rather than opening in the lightbox.

  • Esther

    So, I added the text to the top of my functions.php file, and this is the error I got when I tried to update a post – the custom url field showed up, I was able to modify it in my posts, but when I updated and went to preview, this is the error I got (full paths removed): 

    Warning: Cannot modify header information – headers already sent by (output started …functions.php:46) in …theme-editor.php on line 99
    Any ideas on what’s wrong?

  • Esther

    So, actually when I went to refresh my whole site, I got a different error – a syntax error – so I had to remove the <?php that was at the beginning of my file, since the code I copied and pasted already included a <?php opener. 

    That solved it!

  • Abbe

    I pasted code from pastebin in functions.php, but I dont see any Custom URL field in the gallery.

  • Abbe

    I solved it. For wp 3.2.1 I replaced and put the whole code in media.php instead of functions.php

  • ac

    hi abbe, i tried doing this and something’s going wrong… not an expert coder, just followed directions but must have done something wrong. i took the entire code from pastebin and pasted into the media.php, replacing the gallery shortcode that was there. where could i have gone wrong? thx

  • ac

     never mind! i had forgotten to change the gallery shortcode link….!!

  • Aimee

    Thank you for this code. It works wonderfully. I only wonder if it is possible to modify previous_image_link() and next_image_link() to also point to the custom URL instead of the default attachment page?

  • comercier

    Did you find an answer to the problem? I have the same error that Carolineniland (the double picture) plus that ‘> at the end of the file…

  • comercier

    Can you give more specifics on what you did I’m having a hard time trying to fix those same problems on WP 3.2… Thanx in advance

  • http://www.effutio.com ThePath

    I can confirm this works with WP3.3. Thanks dude, this save my bacon. I to however experienced the double image and the > displayed on the page. I can also confirm this was due to ommitting the new custom_url field in the shortcode: [gallery columns="2" size="medium" link="custom_url"] if you miss this out it will break, got nothing to do with dodgy urls etc as previously suggested in a comment

  • http://nick-brewer.com Nick

    You shouldn’t have to modify the media.php file, I recommend not changing any core files. All code modifications above should be within functions.php in your theme folder.

    After you have pasted all of the code you have to change the link value in your post shortcode to “custom_url”.

  • http://nick-brewer.com Nick

    Thanks for checking it in the latest WP update!

  • http://twitter.com/sev7en_com 尚7科技

    wp3.3 error:   ”input” => ”text”, // default     how to solved?  Thanks

  • Anonymous

    So I got it to work in WP3.3 however I am having the same issue of the double image and > being displayed and I was wondering how to fix this? I am still a newbie to php and any help would be greatly appreciated.

  • Anonymous

    Figured it out! A wonderful work around, thank you.

  • http://nick-brewer.com Nick

    Glad to here! Is the fix worth sharing?

  • Anonymous

    I just forgot to do the last step and change the gallery shortcode link attribute to “custom_url”. That fixes the double image issue, or at least it did for me.

  • Daniel Pol

    Great job. Thanks a lot.
    Yeap, works with 3.3

  • Kelli S.

    This works for me on 3.3 also. I really appreciate your work on this code!! It’s just what I needed!
    Thanks

  • AP

    Added the code to the theme folder as a custom-functions.php file. Works great, thanks for the post

  • http://www.facebook.com/alphaalec Alec Morrison

    This is holy crap awesome. Exactly what I needed for a client. WordPress needs to implement this fine piece of work. Many thanks!

  • Philip John

    I wish this was part of core ;) Any reason why it’s not a plugin and on WordPress.org ?

  • http://nick-brewer.com Nick

    I should probably get to that, it really should be a plugin… Didn’t expect so many people to need this.

  • http://www.facebook.com/naynayell Nikz Elliott

    Ohh god this is too much for me lol  I’m a complete
    noob, 0 PHP knowledge :( been trying to add the first code and I’m not even
    sure if it’s the right place to put it.

    Here is where I’m trying to put it:

    public_html/domain/wp-content/themes/theme/functions.php

     

    when I open it, there is only this –

     

     

    I tried adding code after “?>” and before, either

     

    If I put it before I get this error

    Parse error: syntax error, unexpected ‘=’, expecting ‘)’ in
    /home/cicomum/public_html/rpgflashgames/wp-content/themes/goodnews/functions.php
    on line 13

    And if I put it after “?>”

    I get this code on top of my dashboard

    Help please L(

     

     

  • http://vickistep.tumblr.com vickistep

    Hi. Thanks for all of the time you’ve put into this fix and answering questions.

    I’ve got the fix working fine on the default WordPress gallery, but when I activate a gallery plugin like Polaroid Gallery, which also uses the default gallery shortcode, I cannot get the custom URL to work. The images still link to the image files. Would you have any advice on how to make the plugin cooperate with the fix?

    See here: http://mcduffys.com/sample/

    I did try pasting your fix into the “polaroid-gallery.php” plugin file but it just did the same exact thing that it does now. The fix is currently pasted in my theme’s “functions.php”

    Sorry I know this isn’t your plugin but it seems that there are lots of people posting on the plugin forum looking for the same fix. I’d be happy to share my findings with them and a link back to your site.

  • http://nick-brewer.com Nick

    That plugin is either adding it’s own shortcode or overriding the default. I believe the only way to get it to work would be by modifying the polaroid gallery plugin directly. Which would require editing their existing code not adding anything new.

  • Barry

    Hi, Im running latest wordpress and latest theme Trending – the Input field in Gallery is visible after inserting this code into my Trending Theme functions.php, but does not recognise the new custom link url (HTML modified to: [gallery link="custom_url" columns="4"] )

    Any advice? This is such a great mod, its a winner as a plugin ;-)

  • http://nick-brewer.com Nick

    Hey Barry. I just finished moving the code into a WordPress plugin. Let me know if you are still having issues after adding the plugin. I’m not sure what could be the issue except for maybe if you are using another gallery plugin. https://github.com/brewern/gallery-custom-link

  • http://nick-brewer.com Nick

    I’ve moved my code into a WordPress plugin. Place the downloaded folder into your plugins directory https://github.com/brewern/gallery-custom-link

  • http://nick-brewer.com Nick

    It’s now a plugin! :)  https://github.com/brewern/gallery-custom-link

    I’ll work on getting on WordPress.org

  • Barry

     Hi Nick, thanks for the quick reply and the news on the plugin – I will definitely be using it.

    I managed to get the code to work with some changes suggested by the Trending theme author, so I think it was a theme issue. If anyone needs it I can post, but I guess not necessary with your plugin.

  • http://www.facebook.com/rferent Robert Ferent

    I, too, am a n00b and know virtually nothing about code. I believe I followed the install process correctly. I’m getting the following error in the gallery…

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘GalleryCustomLink::rt_image_attachment_fields_to_edit’ was given in /miraclemen.info/wp-includes/plugin.php on line 170

    The plugin is in my “wp-content/plugins” directory in a folder titled “brewern-gallery-custom-link”. I’m using WordPress 3.3.1 with theme Twenty Eleven 1.3

  • shlomi

    from were i need do downloed the plg?

  • Jp

    by the way, the 170 line in the plugin.php file looks like this:

    $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));

  • Jp

    im getting the same warning

    any ideas on how to fix it?

  • http://nick-brewer.com Nick

    Sorry about that, I rushed posting about the code and didn’t do some error checking. All is fixed and has been tested now.

  • http://nick-brewer.com Nick

    Sorry about that, I rushed posting about the code and didn’t do some error checking. All is fixed and has been tested now.

  • http://nick-brewer.com Nick

    Click on the Github link at the top of this article, then in the mid-header area of that page there is a “zip” download option. Click that link and you will get a zip file of the plugin.

  • Jp

    Thanks a lot man! im gonna try this right now!

  • shlomi

    hi
    Claim plugin should resolve after you have installed it is actually saving the imageTlink I wantBut once I’m up to and updating after I click the image appears an error:You do not have permission to access / wordpress 2 / <a href = on this server.What am I supposed to do all my site-based to a gallery of images on the main page and bereavement image linkAnother postI use warmserverPlease help me 

  • shlomi

    hi 
    thanks allot it what i need 
    afther i downlodad the post and click on the image 
    You don’t have permission to access wordpress on this server. 
    i workin on wampserver 

  • http://nick-brewer.com Nick

    I don’t think the issue is with this plugin. Check the php file’s permissions, does it match the permissions on other plugin files? Your OS may have the file permissions changed to something else as a result of the download and WordPress doesn’t like it.

  • Chappers

    I tried this a few days ago but it totally screwed my site – I ended up having to reinstall wordpress – bad times.  As others are saying how successful its been I guess I did something wrong with it.  Being a total newbie, can someone let me know how this is supposed to be installed?  Cheers

  • Chappers

    You know what, I’ve been a total moron…..!!  I did do something wrong with it!! Ooops!  Managed to get it installed now and it seems to work beautifully.  Cheers. I can’t believe this isn’t part of the standard set up.

  • Bavarskiss

    It’s a great feature, but I can’t get it working. The new field “custom link” appeared, but it doesn’t seem to have any effect. I added [gallery link="custom_url"] in html, gallery works, but doesn’t link to external url. I am using WP 3.3.1 version. Any ideas what I may be doing wrong?

  • Thartsf

    This appears to not work for me, do I add the code [gallery link="custom_url" columns="2"] in the post?  I did that, in the html of the WYSIWYG dashboard and nothing happened. I even added [gallery link="custom_url" columns="2"] in the .php template of the page in the proper theme, but the code appears as string like the server did not interpreted the code. Any Ideas? I am using the free theme parallax porfolio…..

    I can  see the custom URL field, so it does partially work…

  • http://nick-brewer.com Nick

    This is just as much work as what I’m recommending. Either way you have to add a plugin and type in a link, there may be a few less steps using the plugin I’ve provided. Also it seems kind of odd to have to set up redirects when you just need to link out.

    Also you may want to link to the image page in one area but have a different link from the galleries.

  • coffeeej

    Awesome… worked perfectly as a plugin. You need a donate link!  Would probably be helpful to others struggling with installation to add it to the WordPress Plugins Page.

  • Anonymous

    i love you.

    2 weeks of searching for a way to do something so elementary and just now i found this plugin. i really appreciate it. can’t believe this isn’t built in.

  • Mbetterly

    I tried it and it didn’t work with F8 static theme. I’m on WP 3.3.1. I get a double image and an error when I click on the image (404). I’ve tried all types of URLs – nothing works. Please assist.

  • Jack Jamieson

    Just set this up on a site I’m building – Works perfectly and is easy to use.  Thanks!

  • Marja

    I don´t know what I´m doing wrong but I cannot get this to work.
    I´m using:
    wp 3.3.1 & the headway theme
    I installed the plugin and uploaded the images afterwards.
    [gallery columns="2" size="medium" link="custom_url"]

    The custom url gets ignored and the urls stays like this:
    http://domain/gallery

  • Guest

    Hi, not sure how you install this plugin. Not sure either if I’m downloading the right file. Thanks

  • marbie design

     I figured it out myself already.It´s the code of the slider plugin(in which the gallery images are showing), that´s generating the url and therefor ignoring the custom_url

  • Waarboks

    How do you install this? Get 
     PCLZIP_ERR_BAD_FORMAT (-10) as error when i try to upload the php file

  • Frank

    Please, send this plugin to the WP core team and see if they can incorporate it into the next version of WP. Such a simple feature that’s been so badly needed in the gallery for a long time. Thanks for your work!

  • http://nick-brewer.com Nick

    Add the shortcode to your post wysiwyg editor, I believe not in the HTML tab.

  • http://nick-brewer.com Nick

    Does that theme modify the Gallery at all? Are you using a Gallery plugin?

  • http://nick-brewer.com Nick

    Download the zip file from Github. Place that folder in your plugins folder.

  • http://nick-brewer.com Nick

    Place the downloaded folder into your plugins directory. Then enable it from the WordPress admin.

  • http://www.facebook.com/damiano.morosi Damiano Morosi

    Does anyone use it for retrieving custom url from theme? I tried:

    $image->custom_url

    (obviously into the loop) but id doesn’t work. I don’t know if it’s possible or not… thank you!

  • Nathan

    Worked like a charm. Was about to write the same plugin, thanks for your effort!

  • http://www.facebook.com/people/Guillaume-Forcade/687929532 Guillaume Forcade

    HI, thank you for the plug-in.
    I am wondering how to get the link from the image to open in a new tab or new page (and not in the same one like it is at the moment). Is there any simple way to add a line of code somewhere to get the job done?
    Cheers

  • Cgero

    I have installed and inserted the code, but I keep getting this error “Image cannot be loaded. Make sure the path is correct and image exist”. I notice in my gallery, when I add the link in the custom link field to the image and save, the custom url disappears. It doesn’t seem to be saving the link to the image, but instead using the image path as the link? Can you help : (

  • Icedms

    Hi – Thanks for a wicked plugin, I’ve been looking for something like this for weeks :) Now all I’ve got to do is get it working properly lol
    I’m using the Oracle theme which doesn’t appear to make any changes to the WP gallery. I’ve tried the plugin on two sites one local and one live same problem when I click on the image I just get a timer. Tried it on Quantum theme, same issue. I’ve just switched to the ‘Twenty Eleven’ theme and it works perfectly :) So I guess I’ll have to go and ask the theme makers. I’ll leae the post though just in case someone else has the same problem, if I get an answer I’ll come back an let others know.

  • http://nick-brewer.com Nick

    This wouldn’t be difficult to add. It would require a checkbox option below the custom link for “open link in a new tab”. I’ll get to this soon.

  • http://nick-brewer.com Nick

    What version of WordPress are you using? What theme are you using?

  • Cgero

    I am sorry I should have included that, Theme: Dandelion v.2.6.1, WordPress 3.3.1. The odd thing is that the url field shows up, but when you save it won’t apply it to the image.

  • Anonymous

    Does it matter if the Link URL is still in there? Or do I delete it and just paste in the Custom URL? 
    Thanks

  • Anonymous

    I did all the steps above and nothing worked. :-(  
    Bummer!!!

  • http://twitter.com/roraz Roraz

    This plugin is exactly what I was looking for, but after installing it, found out it doesnt work due to it conflicting with the Cleaner Gallery plugin which I have installed (and really don’t want to uninstall) :(

    Its a shame as even in the Cleaner Gallery Settings theres an option to specify what gallery Images should link to by default (eg attachment page, full size image, various sized thumbs etc), except the custom link option created by this plugin doesnt appear there…

  • Susie

    Hi Nick – thanks for the pluggin! However, when I use it, it doesn’t seem to override the link to image or file. When I edit an image in the gallery, the custom url box is displayed, I put in my url and clear the above link info to none. That all works fine. I save changes and go to the html on the post and change to have [gallery link="custom_url"...]. All the operating is fine, but when I test, the image links to file or attach page (defaults).

    When I go back to check what has happened, the edits made to the gallery image are fine, but the general box at the bottom still has a radio button choice of linking to file or attachment. So, it seems that the code isn’t overwriting the general box direction that is at the bottom of the gallery page for all images.

    Is there anything else I can do to make this work? Thanks sooo much for the pluggin! Susan

  • Shamguy4

    than the lord i found this. i kept going into the html editor and just changing the anchor link to my own but it didn’t register and continued using the file url which was useless
    now if there was a way to remove from gallery without deleting the image….that would be great

  • http://nick-brewer.com Nick

    When you install this plugin it will create a new custom URL field that will be blank. It shouldn’t have the file URL in it. You may be looking at the File URL field not the Custom URL field.

  • http://nick-brewer.com Nick

    You don’t have to clear the Link URL to none. If the custom url is present it will override the link. Does your theme modify the images or custom the gallery at all? Maybe a gallery plugin you are using?

  • http://nick-brewer.com Nick

    I bet that theme is making it’s own changes to the gallery function. This will overwrite any gallery changes my plugin writes. I will look into a way to prevent this from happening, if it’s possible.

  • zip zip

    Thanks Nick – I am asking the developers now, the theme is Hatch Pro by DevPress and it seems like a pretty straight-forward approach for the galleries. It would be super amazing if I can get this to work, since then I will be able to use the mobile part of the them and all. Right now, I just have a bunch of images placed next to each other with custom links on each—opens the organizing of these images to be left up to the ways of the web!

    Thanks for putting the pluggin out there! Susie

  • zip zip

    Nick, I have confirmed that the theme does not modify the  standard WordPress behavior regarding the image galleries. Any help you can lend to make this work is GREATLY appreciated! Thanks. Susie

  • Mr. Ken

     Felix the code you provided to modify is the code, is identical to the code we want to modify.  You you please review this and correct what we shoul replace it with thanks

  • http://www.kreatx.com/ Lejdi Koci

    Saved me a headache :) Thanx a lot!

  • Punkrawkshoe

    I am having the same issue. I am not using any gallery plugins besides yours. My theme does not modify the gallery. using wp 3.3.2. I get double images and they have a “> between them.

  • Punkrawkshoe

    Solved. forgot to put a _ between custom_url

  • Plugin

    Thanks so much for this… this is a great plugin that works exactly as it should.

    No idea why this isn’t built in to wordpress?!? Seems like common sense that you should be able to link to a URL from a gallery.

    Love you.

  • Pennyhunter12

    Can I have a custom url for the images in my gallery if my blog is a wordpress hosted blog?

  • http://vickistep.tumblr.com vickistep

    I’m afraid that I’m missing something here. How do I install the plugin if the file you’re providing on github is just a single php file? I created a folder /plugins/gallery-custom-link/ and placed the php file inside there – but it wont let me activate. Are there missing instructions?

  • http://vickistep.tumblr.com vickistep

    Ugh. nevermind. I found the button on GitHub to download the zip and that worked. 

  • Hamedrx

    I have same problem! how to solv?

  • JJ

    I’m afraid I’m one of the slow people.  When I choose to download as a zip file, it tells me the file cannot be saved. 

  • Claudia

     Hi, can you give more explanation about it? I’m having the same problem

  • http://twitter.com/leeuniverse Allen D. Lee

    Hey, an FYI….  This plugin doesn’t work with the “File Gallery” plugin….  get a 404 error, and hovering over the image shows a the link up to “custom_url”, doesn’t show the actual link.

    I would be good if it could, so we could add more than one gallery to a page, and we can choose how our media files videos, swf’s etc display, like if we want to do an image through the gallery, or use the File Gallery default image for videos etc. to display it.

    Thanks.

  • http://www.facebook.com/Mathias.Oddity Mathias Erixon

    Is it possible 

  • http://www.facebook.com/Mathias.Oddity Mathias Erixon

    How do I change the default “linkstate” to Image file instead of Attachment Page in case the custom url is not set? Is that possible. 

    I use gallery together with PrettyPhoto and I have a videolink on one or two gallery thumbs, but I would like the rest to default to “Image File” thumbnails instead of Attachment page dito. PrettyPhoto needs ”Image File” links it seems.

  • Anonymous

    Great plugin thank you 

  • Rowena Padel

    Hi – you cannot believe how much I need this plugin. I am working with a custom theme that I’ve built myself that doesn’t do anything to the WordPress Gallery but I do have NextGen Gallery plugin installed to control the actual photo galleries. I need this on a completely different part of the site to link out to items on an associated shop, but the custom url doesn’t override the Link URL. I have added custom-url to my shortcode.
    Could the NextGen Gallery plugin be overriding things?

    Another call from me for this to be put into the WordPress core code!

  • Matthew Therrien

    Hey thanks so much – works perfectly even up to WordPress 3.3.2 but FYI – you will get sa Submission Error if you use this with jQuery Lightbox For Native Galleries – as the image tries to load in a Lightbox and then execute the custom URL

  • http://www.facebook.com/people/Zen-Cart-Dev-Team/100002760799142 Zen-Cart Dev-Team

    Works great even up to WP 3.3.2 but FYI – you will get a Submission Error if you use this with jQuery Lightbox For Native Galleries – the image loads in Lightbox and then tries to execute the Custom URL and errors – but other than that – this is a great contribution!

  • http://www.facebook.com/people/Zen-Cart-Dev-Team/100002760799142 Zen-Cart Dev-Team

    We will do the mod for Open File In New Tab and post a link once we have got it ready 

  • Irenef+geekmedia

     You must put the call like that, and now works!!!!:
    [gallery link="custom_url"]

  • Yadi

    Thank You, It’s works on mine

  • koooba

     great plug and great news about “open in the new tab” checkbox coming up….when can we expect it to be ready??

  • http://goo.gl/jNu3Y The New Fulcrum Point

    Awesome post! Thanks a lot!

  • Mark

    I’m also waiting for the moment that “open in the new tab” is available. Can you give me more information when the moment is there?

  • Anonymous

    Hi, great simple plugin.  Just wanted to post that I was having trouble getting it to work properly, and discovered that it was because it interferes with the Roots wordpress starter theme (which I use on most projects).  To fix, just find the function called “roots_gallery_shortcode” in the inc/cleanup.php file and delete it. 

    I think this function was just used to reformat the gallery markup to play nice with  Twitter Bootstrap, which I’m not using, so a simple delete was enough for me.  Just thought I’d post my results in case anyone else is having issues…

  • http://www.facebook.com/adedoyin.kassem Adedoyin Kassem

    Nice post. However, I am trying to do something entirely different for client’s portfolio and was hoping you could help out. Now, I want to create a link (could be either text or image) that when clicked on would open a specific wordpress gallery (e.g. [gallery-1]). 

    Can you help out with this..?

  • Josepaitamala27

     Also looking forward to to see the check box for Open File In New Tab, thank you for the plugin!

  • Matz

    Thanks!!!

  • Anonymous

    fantastic, I spend days looking for solution which I have now founds thanks

  • RRR

    Please, can anyone tell me how do I install the plug-in?
    I uploaded the php file to the plug-in directory, but it doesn’t show in the installed plug-in page of WP.
    Am I missing something? How do I install and activete?

  • http://nick-brewer.com Nick

    The php file must be in a folder named “gallery-custom-link” inside the plugins directory. Then it should show up in the admin on the plugins page.

  • RRR

    I managed to install and activate now, was naming the folder wrong, but it’s still not working. Does it work with twenty-ten theme? Or else, do you have a list of themes with which the plugins work? Please. I desperatly need to use your great plug-in!

  • RRR

    Anh, no I didn’t, I installed the gallery url plug in, note the images in a gallery self url plug-in….my first question stands, please let me know what I’m doing wrong,…

  • http://www.facebook.com/profile.php?id=594728609 Jimmy Castellano

    Your plugin works like a charm….i love it. Thank you so much. The part i was confused with was the ” Go to the HTML tab of the WordPress Wysiwyg and change the gallery shortcode link attribute to “custom_url”. But I figured it out…after that it worked fine.  For anyone else who is not understanding that part, it means, that AFTER you have created the gallery…..then click on the HTML tab on top right and you will see the code as written in the above screen shot.. then just put in the    custom_url    instead of the word     file.   it is all good!!!

  • Caryn

    Thanks a bunch – works for exactly what I was looking for – cheers!

  • PPK17

    Just wanted to say thx for this plugin. I tried using laziest gallery plugin but the problem was whether you use a image inside the page where your gallery is, that image of the page doesnt disappear when you display an image of the gallery, was kinda annoying. Anyway, thx again for sharing this.

  • Tasadam

    I am using this plugin to open a link to a separate website for each image.How can I make it to open a link in a new tab instead of opening in the current window in my browser?I imagine I would have to edit the plugin file, but I don’t know enough about code to know what to stick in, or where…
    Can anyone advise?Thank you and regards.

  • Tasadam

    +1. Should have read the comments before posting.

  • Sassy_az

    sorry i am unsure how you add this plugin

    thanks 

  • Susan

    hi Nick, thanks for sharing this plugin. Just wondering if that ‘open in new tab’ option is ready yet?

  • http://twitter.com/nickatadistance NICK VECCHI

     Havng trouble.! Could anyone point to a step by step or a YouTube video of how to get the links right. I have the plugin installed but am really struggling to get it right.
    Thank you in advance.
    Kindest

  • Yoonmi76

    ugh so close to a solution – but doesn’t seem to work for me…I get the “after” where it gives a text box for the url – set it to [gallery link="custom_link"] but it never actually links to the custom link. I don’t know what I’m doing wrong. 

  • http://twitter.com/roraz Roraz

    Is this plugin compatible with the latest WordPress release, as I literally have no other plugins installed, hacks etc and the thumbs aren’t linking to their respective urls, just the usual image attachment urls?!??

    And I have specified the link as custom_url fyi ;)

  • Solaceten

    The one issue I do have is the HTML link [gallery "custom"] dissapears if you make any edits to the gallery – you have to re-add that. Would be good if the plugin could “remember” that setting when updating the gallery images, links or captions etc….

  • Solaceten

    To make links open in new window just modify code on line 147 to this

    a href=’$attachment_meta’ target=’_new’

  • Lewisrowlands90

    hey, does it not work with the newest version?

  • Usman Ashraf

    Hi! I want some help about wordpress.
    I want to add a widget of links in my website sidebar. I want to add to add images which have some url’s. I want to add multiple images in that widget. Can you suggest me any wordpress plugin which such qualities. Please please help me in finding that widget. My email is ashrafusman93@gmail.com 

  • Guy Lev

    Hi There
    I think that the plugin break in wordpress 3.5
    It completely ignores my custom link….
    http://80.179.140.91/~discretix/?page_id=12
    Appreciate any help :)
    Tanks
    Guy

  • Mattwad

    The file on Git now requires you to use [gallery link="custom"]. Please document for others, I was about to give up on a great plugin!

  • Dani

    I’m trying the plugin with the last version of wordpress and doesn’t work. The image is linking the file althoug I change the custom url

  • http://nick-brewer.com Nick

    Thanks Matt! Didn’t realize the merge I made recently had changed that. Post has been updated, and a ReadMe added to Git.

  • http://nick-brewer.com Nick

    Dani, try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect. Sorry for the inconvenience.

  • http://nick-brewer.com Nick

    Guy Lev, try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect. Sorry for the inconvenience.

  • http://nick-brewer.com Nick

    It does, there was a change that was not documented that likely was the cause of your issue. Try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect. Sorry for the inconvenience.

  • http://nick-brewer.com Nick

    Roraz, try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect. Sorry for the inconvenience.

  • http://nick-brewer.com Nick

    Yoonmi76, try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect due to an update. Sorry for the inconvenience.

  • http://nick-brewer.com Nick

    Yoonmi76, try using [gallery link="custom"]. I’ve updated the post, the previous example was incorrect due to an update. Sorry for the inconvenience. Hope this helps.

  • Danilo Roncevic

    You just made my day. Thanks a lot.

  • Samanthamum

    This is the best thing I’ve ever seen. Thank you!

  • simon

    You are my hero!!!!!

    Thanks alot mate, keep up the good work!