Notifications
Clear all

I have to add this code after every update.

2 Posts
2 Users
0 Reactions
182 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: 5437
 Sofy
Admin
(@sofy)
Support Team
Joined: 7 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