Remove file extension from media title


#1

Hi, we would like to remove file extention (.jpg, .png, etc) from displayed title, do you know if we can use a native php function which could do it :wink: automatically ?


#2

Hi @Laurett,
Sorry in delay in reply.

Yes it is possible be changing the template file : media-gallery-item.php

You need to use function trim_extension( rtmedia_title() ) in place of rtmedia_title().

And put the following function in your functions.php file:

function trim_extension($filename) {  
        if($filename){  
            $temp = explode( '.', $filename );  
            $ext = $temp[sizeof($temp)-1];  
            if(in_array($ext, array('jpg', 'png'))){  
                array_pop( $temp );  
            }  
            $name = implode( '.', $temp );  
            return $name;  
        }  
        return false;  
    }

#3

Really not an emergency, don’t worry :wink: thank you @abhishekkaushik for sharing this function

Well, found it in the following media-single.php file but it seems there is an orther file which generate media title in activity wall(s) and status update pages, isn’t ?

please, could you tell me where do it in order to apply it in BP activity / single update pages ?


#4

@laurett,
Currently there is no such filter to edit media title in activity. Though we add filter, BuddyPress stores the whole HTML content of activity update in database. So, after applying new filter,it will affect only new activity updates and not the old one which are stored in database.


#5

#6