media_type === 'photo' ) { // Check if we are on the activity component page or group activity page. if ( bp_is_activity_component() || ( function_exists( 'bp_is_group' ) && bp_is_group() ) ) { // Retrieve the URL for the custom image size. $image_src = wp_get_attachment_image_src( $media->media_id, 'custom_rtmedia_size' ); // Check if $image_src is a valid array and contains a non-empty URL. if ( is_array( $image_src ) && ! empty( $image_src[0] ) ) { // Sanitize the URL to prevent XSS. $custom_image_url = esc_url( $image_src[0] ); // Replace the old image URL in the HTML with the new custom URL. $html = preg_replace( '/src="[^"]*"/', 'src="' . $custom_image_url . '"', $html ); } } } } return $html; } add_filter( 'rtmedia_single_activity_filter', 'buddyx_custom_rtmedia_filter', 10, 2 );