This is driving me insane. Am I the only person who thinks this is a problem?
I agree. Seems totally daft.
The hyperlinks aren’t even given a class by default so my idea to put the linked image in a modal dialogue doesn’t even work!
Gotta be a workaround for this somewhere…
Found quite a nice solution to open the linked images in a modal dialogue – I use colorbox as it’s easily the best (jQuery modal dialogue) and very easy to customize.
I added the following to functions.php:
add_filter('the_content', 'addColorbox');
function addColorbox ($content) {
global $post;
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="colorbox"$6>';
$content = preg_replace($pattern, $replacement, $content);
$content = str_replace($pattern, $post->ID, $content);
return $content;
}
Which adds a rel="colorbox"
to hyperlinked images.
Obviously you have to link to jQuery and colorbox in the <head> section of your page, but the following simple call will sort you out:
$('a[rel="colorbox"]').colorbox();
Colorbox – and WordPress of course – both allow you to specify a max width / height to stop the linked image taking over the entire screen!
Of course you could use any modal dialogue – there’s even a plugin that will let you do this without getting your hands dirty!
Run this in theme’s functions.php or plugin file. This will set the default for any future usage. Choose one:
None: update_option('image_default_link_type' , '');
File URL (this is WordPress default): update_option('image_default_link_type' , 'file');
Post URL: update_option('image_default_link_type' , 'post');
Optionally, browse to http://yourblog.com/wp-admin/options.php and find image_default_link_type
. You can also set from there.
Very cool. Thanks Zeo. I’m kinda scared to mess with functions. Will this mess up future upgrades to wordpress?
If you put it in your functions.php file, in your theme, then NO, upgrades won’t affect it unless the function you change is deprecated. Which in this case? Highly unlikely π
IMO? NEVER EDIT CORE!
how exactly do I set it from options.php?
it”s difficult for me to understand since i haved used English for too long .
OK…. so I did this and new authors are apparantly still getting the link by default. Is it possible something is wrong with that code? What’s the exact way to include it?
update_option('image_default_link_type' , '');
Like, do i just past that exactly in there? Isn’t there supposed to be some <?php something or other around it?
Hey, anyone got an obvious solution other than the one above? I added that line to options.php and no luck, new users still are doing the dang link by default
I’m pretty sure Zeo didn’t mean for you to actually edit the options.php file. I think you should undo the lines you edited there.
Did you try Zeo’s 2nd suggestion of browsing to http://yourblog.com/wp-admin/options.php while you’re already logged in to the Dashboard?
You should see a huge list of settings, and when you find that setting for image_default_link_type, it’s probably set to ‘file’, which you want to clear out and then click Save at the bottom of all of the options.
woah. I had NO idea that page existed. Thanks!
So, curiously, it is in fact blank. I will have to double check this, as what I actually edited was functions.php, not options, so maybe this was already ‘fixed’, but I swear new users are still getting the stupid link in there. I’ll have to do an experiment. Stand by.
When you edited functions.php, that line of code did blank out that option. What happens when you change tbat option from blank to ‘post’ ?