I use filter for change link for attachments in a page
function custom_attachment_link($markup, $id, $size, $permalink, $icon, $text) {
// Get attachment meta data
$attachment_meta = wp_get_attachment_metadata($id);
if ($attachment_meta) {
// Get the file size
$file_size = size_format(filesize(get_attached_file($id)));
// Get the file type
$file_type = $attachment_meta['mime_type'];
// Debugging: Output file size and type
error_log("File size: $file_size, File type: $file_type");
// Add size and type to the link markup
$markup .= '<span class="attachment-meta"> (' . $file_size . ', ' . $file_type . ')</span>';
} else {
// Debugging: Output if metadata is not available
error_log("Attachment metadata not available for attachment ID: $id");
}
return $markup;
}
add_filter('wp_get_attachment_link', 'custom_attachment_link', 10, 6);
but this code not modified links in page content. What is wrong with this code?
functions.php
or a plugin?functions.php