Mar 06, 2019 8:31 pm
Hi, I use wpForo with addon embeds. Can I somehow make the post uploaded a photo, it was displayed as a photo and not as a link, see the attached picture on link.
Thank you.
8 Replies
Mar 06, 2019 8:57 pm
You can do that with the attachments addon
Mar 06, 2019 10:18 pm
Also try this in your theme's functions:
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' ){
$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;
}
https://wpforo.com/community/how-to-and-troubleshooting-2/uploading-and-embedding-images/#post-5212
Nov 15, 2021 7:21 am
I have added that code snippet too, and it worked a treat for showing one image in a post. Thank you! However, if I go back to edit any post with an image displaying, then I save the edit, the photo then reverts back to being displayed as a link. Any ideas please? Many thanks.