我正在尝试向“插入媒体”模式添加文本输入,希望能够添加html5data-
属性设置为图像的父锚点。
<a class="fancybox" href="..." data-fancybox-group=" ">
<;--此部分<img class="wp-image-871" src="..." alt="..." width="245" height="333" />
</a>
到目前为止,我已经能够将输入添加到模式:
在我的函数中使用下面的代码。php文件:
function add_fancybox_input( $form_fields, $post ) {
$form_fields[\'fancyboxGroup\'] = array(
\'label\' => \'fancybox group\',
\'input\' => \'text\',
\'value\' => \'testing\',
\'helps\' => \'use this to group images in fancybox\',
);
return $form_fields;
}
add_filter( \'attachment_fields_to_edit\', \'add_fancybox_input\', 10, 2 );
我添加了data-fancybox-group=""
至锚,使用:function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = \'\' ){
$classes = \'fancybox\'; // separated by spaces, e.g. \'img image-link\'
// check if there are already classes assigned to the anchor
if ( preg_match(\'/<a.*? class=".*?">/\', $html) ) {
$html = preg_replace(\'/(<a.*? class=".*?)(".*?>)/\', \'$1 \' . $classes . \'$2\', $html);
} else {
$html = preg_replace(\'/(<a.*?)>/\', \'$1 class="\' . $classes . \'" data-fancybox-group="" >\', $html);
}
return $html;
}
add_filter(\'image_send_to_editor\',\'give_linked_images_class\',10,8);
这就是我被困的地方。。。我有一个地方可以输入数据,也有一个地方可以存放数据,但我不确定如何从数据fancybox组属性的输入中获取数据。