Wordpress 如何在古腾堡画廊的链接中添加rel atribute

Wordpress 如何在古腾堡画廊的链接中添加rel atribute,wordpress,image-gallery,fancybox-3,wordpress-gutenberg,gutenberg-blocks,Wordpress,Image Gallery,Fancybox 3,Wordpress Gutenberg,Gutenberg Blocks,如何在我的网站上使用fancybox 3。我将此代码用于旧图库: add_filter('wp_get_attachment_link', 'rc_add_rel_attribute'); function rc_add_rel_attribute($link) { global $post; return str_replace('<a href', '<a data-fancybox="images" href', $link); } add_filter('wp_get_at

如何在我的网站上使用fancybox 3。我将此代码用于旧图库:

add_filter('wp_get_attachment_link', 'rc_add_rel_attribute');
function rc_add_rel_attribute($link) {
global $post;
return str_replace('<a href', '<a data-fancybox="images" href', $link);
}
add_filter('wp_get_attachment_link','rc_add_rel_attribute');
函数rc_add_rel_属性($link){
全球$员额;
返回str_replace('
add_filter('the_content','aggiungi_fancybox');
函数aggiungi_fancybox($content){
全球$员额;
$pattern=“/post_title.”“$6>”;
$content=preg_replace($pattern,$replacement,$content);
返回$content;
}
添加过滤器('u内容','aggiungi\u fancybox');
函数aggiungi_fancybox($content){
全球$员额;
$pattern=“/post_title.”“$6>”;
$content=preg_replace($pattern,$replacement,$content);
返回$content;
}

此函数可与fancybox 3的数据fancybox属性配合使用。您可以修改“标题属性”。虽然此代码可以回答该问题,但提供有关此代码回答该问题的原因和/或方式的附加上下文可提高其长期价值。此函数与fancybox 3的数据fancybox属性配合使用效果良好。您可以修改“title属性”。虽然本准则可以回答该问题,但提供关于本准则为什么和/或如何回答该问题的附加上下文可提高其长期价值。
add_filter('the_content', 'aggiungi_fancybox');

function aggiungi_fancybox($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 data-fancybox="gallery" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
}