Jun 25, 2025 5:23 pm
Hello,
I am trying to upload a photo (attach file). Unfortunately, only the link (Displayed as a paperclip with file name) to the photo is displayed.
How can the image be displayed directly in the forum?
I found Robert's code (for functions.php, but it does not work).
4 Replies
Jun 25, 2025 7:01 pm
SOLVED!
My fault, found the mistake. Browser translate the code in german ... 🤣
---
add_filter('wpforo_content_after', 'wpforo_default_attachment_image_embed', 11);
function wpforo_default_attachment_image_embed( $content ){
if( preg_match_all('|<a class=\"wpforo\-default\-attachment\" href\=\"([^\"\']+)\"[^><]*>.+?<\/a>|is', $content, $data, PREG_SET_ORDER) ){
foreach($data as $array){
if(isset($array[1])){
$file = $array[1];
$e = strtolower(substr(strrchr($file, '.'), 1));
if( $e === 'jpg' || $e === 'jpeg' || $e === 'png' || $e === 'gif' || $e === 'bmp' || $e === 'webp' ){
$filename = explode('/', $file); $filename = end($filename);
$html = '<a href="' . esc_url($file) . '" target="_blank"><img class="wpforo-default-image-attachment" src="' . esc_url($file) . '" alt="' . esc_attr($filename) . '" title="' . esc_attr($filename) . '" /></a>';
$content = str_replace($array[0], $html, $content);
}
}
}
}
return $content;
}