Link Media to direct file, instead of media page

When showing the Media type by CVPro, by default the media link is URL of the media page where:
– shows the image, if the media is an image
– shows the player, if the media is an audio or a video
– shows the title (includes link) of PDF file, if the media is a PDF file

If you want to link the media to its file directly, please add this code to file functions.php in the theme’s folder:


// Content Views Pro - Link Media to direct file, instead of media page
add_filter( 'pt_cv_field_href', 'cvp_theme_field_href', 100, 2 );
function cvp_theme_field_href( $args, $post ) {
	if ( get_post_type( $post->ID ) === 'attachment' ) {
		$url = wp_get_attachment_url( $post->ID );
		if ( $url ) {
			$args = $url;
		}
	}
	return $args;
}

Best regards,