Support » Plugins » how to insert media with link to file (size=large)

  • Resolved photocurio


    If I use the Insert Media button to add an image to a post, I have four options for a link:
    a. custom URL
    a. attachment page
    b. media file (this is always the full size file, which might be 3000 pixels)
    c. none

    I’d like it to link to a smaller media file, perhaps Large, or a custom image size. That would work well with my Lightbox/Colorbox plugin.

    (I know I could find the URL of the custom size and paste it into the custom URL box, but I don’t want to tell a client to do that. )

Viewing 1 replies (of 1 total)
  • I did eventually find the solution to this problem. See Oikos Get Attachment Link Filter.
    Its brilliant:

    function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) {
        // Only do this if we're getting the file URL
        if (! $permalink) {
            // This returns an array of (url, width, height)
            $image = wp_get_attachment_image_src( $post_id, 'large' );
            $new_content = preg_replace('/href=\'(.*?)\'/', 'href=\'' . $image[0] . '\'', $content );
            return $new_content;
        } else {
            return $content;
    add_filter('wp_get_attachment_link', 'oikos_get_attachment_link_filter', 10, 4);

Viewing 1 replies (of 1 total)
  • The topic ‘how to insert media with link to file (size=large)’ is closed to new replies.