• Resolved jamiedust

    (@jamiedust)


    Hi, is there anyway to force a user to always ‘link to file’ rather than the attachment page, as I find the attachment pages ugly and unneccessary, especially when used with documents etc.

    Is this possible either with a plugin or a hack to the back end?

    thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • I would also like to know if this is possible!

    Thread Starter jamiedust

    (@jamiedust)

    Hi

    I have a solution to this, you need to edit the following file:

    wp-admin/includes/media.php

    Go to line 899

    Change the line: $link = get_attachment_link($post->ID);
    to
    ‘$link = wp_get_attachment_url($post->ID);’

    This means that if either option is chosen the image will always link to the image url.

    Then to line 914, simply delete this line, this removes the link to attachment button.

    Let me know if this works for you.

    It´s not a good idea make changes in WP´s core files. Instead, use the following code:

    function custom_attachment_fields_to_edit($form_fields, $post) {
    
        $form_fields["image_url"] = '';
        $form_fields["url"] = '';
    
        $form_fields["url"]["input"] = "hidden";
        $form_fields["url"]["value"] = wp_get_attachment_url($post->ID);
    
        return $form_fields;
    }
    add_filter("attachment_fields_to_edit", "custom_attachment_fields_to_edit", null, 2);

    Hope it helps 🙂

    Thread Starter jamiedust

    (@jamiedust)

    Fantastic!

    I had been trying to find the function to hook into but had no luck. For me this was a temporary solution to get clients started on the right foot (until an update wipes over the changes). I will try this out later, thanks again.

    How do you force a search result (attachment) to link to file?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Force user to link to file, not attachment page’ is closed to new replies.