Notifications
Clear all

wpForo 1.x.x [Solved] how to add image in the post?

5 Posts
3 Users
1 Reactions
3,991 Views
Posts: 18
 kedy
Topic starter
(@kedy)
Eminent Member
Joined: 4 years ago

Hi

 

can someone help me to add an image to the post? So users can add images with the content. My forum ukdigital.in/hub has lots of chances to add images as it related to uttarakhand tourism as well. But, i can't see any option to add image directly in the post as display.

 

I know I can add attachments but that not fulfill my need. I want to show the image.

4 Replies
Sofy
Posts: 4900
 Sofy
Admin
(@sofy)
Support Team
Joined: 7 years ago

Hi @kedy,

You can use the code explained in this support topic to display the attached image file as an image:
https://wpforo.com/community/how-to-and-troubleshooting-2/uploading-and-embedding-images/#post-5212

For an advanced attachment features you should checkout wpForo Advanced Attachment addon:
https://gvectors.com/product/wpforo-advanced-attachments/

Posts: 18
 kedy
Topic starter
(@kedy)
Eminent Member
Joined: 4 years ago

The code work for sometimes but not it's not displaying images for few posts. I have already added the code in function.php file. You can see the example of post - Best School in Haldwani

This problem usually appears when I edit and save the post again. Please guide me with this.

1 Reply
Chris
(@chris)
Joined: 3 years ago

Famed Member
Posts: 3627

@kedy,

Delete the old Code and add the new one:

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);
Posts: 18
 kedy
Topic starter
(@kedy)
Eminent Member
Joined: 4 years ago

I think it's working.. Thank you @chris