wpDiscuz - WordPress Comment Plugin
Share:
Notifications
Clear all

Image URL conversion without link


igor
Posts: 17
 igor
Topic starter
(@igor)
Active Member
Joined: 2 years ago

Hi Guys!

Is there a way to show converted URL images without the source link?

Thanks in advance.

Topic Tags
1 Reply
Alina
Posts: 73
Moderator
(@alina)
Member
Joined: 2 years ago

Hi @igor,

Please put the following  code in the functions.php file of the active theme:


add_filter('comment_text', function ($content, $comment, $args = []) {
$wpdiscuz = wpDiscuz();
if ($wpdiscuz->isWpdiscuzLoaded) {
$content = preg_replace_callback('@src\s*=\s*"(.+?)"@is', function ($matches) {
$file = get_headers($matches[1], 1);
return 'src="data: ' . $file['Content-Type'] . ';base64,' . base64_encode(file_get_contents($matches[1])) . '"';
}, $content);
}
return $content;
}, 999, 3);

Please don't forget to delete all caches and press CTRL+F5(twice) on the frontend before checking.

Also please note the code provided above will change all images as you describe in the post above.

Reply
Share: