As usual, after deciding to post the question, I find the answer myself.
If you’ve come across it before, please be advised that the ‘title’ field has to be changed to ‘data-link-url’ for it to work with wordpress 4.7.2 and possibly for earlier versions.
This be the code:
add_filter('attachment_fields_to_edit', 'large_attachment_fields_to_edit', 0, 2);function large_attachment_fields_to_edit($fields, $post){ if (substr($post->post_mime_type,0,5) == 'image'){ $html = "<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) )) . "' /><br /> <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button> <button type='button' class='button urlfile' data-link-url='".esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) ))."'>Large File URL</button> <button type='button' class='button urlfile' data-link-url='" . esc_attr(wp_get_attachment_url($post->ID)) . "'>" . __('Original File URL') . "</button> <button type='button' class='button urlpost' data-link-url='" . esc_attr(get_attachment_link($post->ID)) . "'>" . __('Post URL') . "</button>"; $fields['url']['html'] = $html; } return $fields;}
You’re supposed to put it in the functions.php of your theme but I just put it inside the site specific plugin (which is just a basic plugin that you create so you can put your modified code there instead)
My site specific plugin has this code:
<?php
/*
Plugin Name: Site Plugin for yoursite.com
Description: Site-specific code changes for yourside.com
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
add_action( 'after_setup_theme', 'default_attachment_display_settings' );
function default_attachment_display_settings() {
update_option( 'image_default_align', 'none' );
update_option( 'image_default_size', 'custom' );
// update_option( 'image_default_link_type', 'file' );
add_filter('attachment_fields_to_edit', 'large_attachment_fields_to_edit', 0, 2);
function large_attachment_fields_to_edit($fields, $post) {
if (substr($post->post_mime_type,0,5) == 'image') {
$html = "<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='"
. esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) )) . "' /><br /> <button type='button' class='button urlnone' data-link-url=''>"
. __('None') . "</button> <button type='button' class='button urlfile' data-link-url='"
.esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) ))
."'>Large File URL</button> <button type='button' class='button urlfile' data-link-url='"
. esc_attr(wp_get_attachment_url($post->ID)) . "'>"
. __('Original File URL') . "</button> <button type='button' class='button urlpost' data-link-url='"
. esc_attr(get_attachment_link($post->ID)) . "'>" . __('Post URL')
. "</button>";
$fields['url']['html'] = $html;
}
return $fields;
}
}
/* Stop Adding Functions */
?>