Link Media to the file itself, instead of the media page

When showing the Media type by Content Views Pro, by default the media link is URL of the media page where shows:
– the image, if the media is an image
– the player, if the media is an audio or a video
– 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,