Notifications
Clear all

Limited Support

Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.

We appreciate your patience and understanding while our team is away. Thank you for being part of the wpForo community!

Merry Christmas and Happy Holidays! 🎄

I have to add this code after every update.

2 Posts
2 Users
0 Reactions
624 Views
Posts: 19
 kedy
Topic starter
(@kedy)
Eminent Member
Joined: 5 years ago

I want to show images in my community topics/posts.

i do this with this code.

add_filter('wpforo_content_after', function( $content ){
	return preg_replace_callback(
        '#<a[^><]*\sclass=[\'\"](?:[^\'\"]*\s)?wpforo-default-attachment(?:\s[^\'\"]*)?[\'\"][^><]*\shref=[\'\"]([^\"\']+)[\'\"][^><]*>.*?</a>#isu',
        function( $match ){
                $html     = $match[0];
	        $file     = $match[1];
	        $pathinfo = pathinfo( $file );
	        if( wpforo_is_image($pathinfo['extension']) ) {
                $html = sprintf(
                    '<a href="%1$s" target="_blank"><img class="wpforo-default-image-attachment" src="%1$s" alt="%2$s" title="%2$s"></a>',
	                esc_url($file),
	                esc_attr($pathinfo['basename'])
                );
	        }
            return $html;
        },
        $content
    );
}, 11);

But i have to add this code after every update. Is there any other way to fix this issue.


1 Reply
Sofy
Posts: 5637
 Sofy
Admin
(@sofy)
Support Team
Joined: 8 years ago

Hi,

You can use the method described here: https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/


Reply