How-to and Troubleshooting
6
Posts
2
Users
2
Reactions
2,289
Views
Oct 11, 2021 12:23 pm
Hello.
We use for ages now a small code provided by the support guys, that each attachment that was a photo, was show inline (embeded) to the body. Worked perfectly well.
Now it seems something changed, and if I EDIT such a post, the image becomes attachment after saving.
Any ideas how to fix this?
Thanks
5 Replies
Oct 11, 2021 12:27 pm
The code is:
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; }
Oct 14, 2021 4:56 pm
14-Oct-2021 16:53:33 UTC] PHP Warning: preg_replace_callback(): Compilation failed: unrecognized character after (? or (?- at offset 23 in /home/wp-content/plugins/custom-functions/custom-functions.php on line 52
Line 52 is
$content
Oct 15, 2021 12:54 pm
Copy and paste the Code again, please. We have updated in my above reply.
Oct 15, 2021 1:31 pm
Works fine now, many thanks.