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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

I 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