WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Force user to link to file, not attachment page (6 posts)

  1. jamiedust
    Member
    Posted 3 years ago #

    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

  2. lumilux
    Member
    Posted 3 years ago #

    I would also like to know if this is possible!

  3. jamiedust
    Member
    Posted 3 years ago #

    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.

  4. rafaelrubirajr
    Member
    Posted 2 years ago #

    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 :)

  5. jamiedust
    Member
    Posted 2 years ago #

    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.

  6. bibo_m16
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic