【发布时间】:2016-03-02 17:17:20
【问题描述】:
我已使用以下代码将一些自定义字段添加到我的媒体附件详细信息...
function aj_attachment_field_audio_url( $form_fields, $post ) {
$form_fields['aj-audio-url'] = array(
'label' => 'Audio File URL',
'input' => 'text',
'value' => get_post_meta( $post->ID, 'aj-audio_url', true ),
'helps' => 'Add Audio URL',
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'aj_attachment_field_audio_url', 10, 2 );
function aj_attachment_field_audio_url_save( $post, $attachment ) {
if( isset( $attachment['aj-audio-url'] ) )
update_post_meta( $post['ID'], 'aj_audio_url', esc_url( $attachment['aj-audio-url'] ) );
return $post;
}
add_filter( 'attachment_fields_to_save', 'aj_attachment_field_audio_url_save', 10, 2 );
?>
我现在不知道如何更改我的 img 标签以包含带有 data-audio_url="" 的新信息。
基本上,只要有一个带有该字段的图像(添加到内容所见即所得)我想将其添加到 img 标签。
如有任何帮助,将不胜感激。
谢谢你
【问题讨论】:
标签: php wordpress filter action hook