您可以使用自定义URL字段来修改每个库图像的附件链接:
以下插件支持此操作:
<?php
/**
* Plugin Name: Custom Attachments Links
* Description: Adds a new media field, to override the default attachment links.
* Plugin URI: http://wordpress.stackexchange.com/a/176668/26350
* Plugin Author: Birgir Erlendsson (birgire)
* Version: 0.0.1
*/
add_filter( \'attachment_fields_to_edit\', function( $fields, $post )
{
$fields[\'wpse_custom_attachment_url\'] = array(
\'label\' => \'Custom URL\',
\'input\' => \'text\',
\'value\' => get_post_meta( $post->ID, \'wpse_custom_attachment_url\', true ),
\'helps\' => "Override the attachment\'s default",
);
return $fields;
}, 10, 2 );
add_filter( \'attachment_fields_to_save\', function( $post, $attachment )
{
if( isset( $attachment[\'wpse_custom_attachment_url\'] ) )
update_post_meta(
$post[\'ID\'],
\'wpse_custom_attachment_url\',
$attachment[\'wpse_custom_attachment_url\']
);
return $post;
}, 10, 2 );
! is_admin() && add_filter( \'attachment_link\', function( $link, $pid )
{
if( $url = get_post_meta( $pid, \'wpse_custom_attachment_url\', true ) )
$link = esc_url( $url );
return $link;
}, 10, 2 );