admin管理员组文章数量:1122846
I have to add an attribute on WP images to add description on Spotlight lightbox. I tried the wp_get_attachment_link filter but it doesn't work.
function add_data_description_link($content, $post_id) {
$description = get_post_field('post_content', $post_id);
$data_description = ' data-description="' . esc_attr($description) . '"';
$content = str_replace('<a ', '<a' . $data_description . ' ', $content);
return $content;
}
add_filter('wp_get_attachment_link', 'add_data_description_link', 10, 2);
Nothing happens. It seems that the filter does not work at all.
I have to add an attribute on WP images to add description on Spotlight lightbox. I tried the wp_get_attachment_link filter but it doesn't work.
function add_data_description_link($content, $post_id) {
$description = get_post_field('post_content', $post_id);
$data_description = ' data-description="' . esc_attr($description) . '"';
$content = str_replace('<a ', '<a' . $data_description . ' ', $content);
return $content;
}
add_filter('wp_get_attachment_link', 'add_data_description_link', 10, 2);
Nothing happens. It seems that the filter does not work at all.
Share Improve this question edited Jun 20, 2024 at 20:42 Stefano asked Jun 20, 2024 at 20:41 StefanoStefano 636 bronze badges1 Answer
Reset to default 0I think from the Media manager if you click on any image/file there are fields on the right side for Alt text and description....
I guess the Spotlight plugin will get these data from there to use.
本文标签: phpAdd an attribute on WP images attachment link
版权声明:本文标题:php - Add an attribute on WP images attachment link 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303087a1931765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论