Use custom/external URL for Title, Thumbnail, Read More button (Pro version only)

Sometimes, you want to link post title to external URL, all things you need to do is creating a new custom field for the post, with name is cv_custom_url and value is the external URL you want to use (click to read about how to add new custom field).

add-custom-field

# For Media Files

If you want to add custom URL for media files, please follow following steps:

  • Install & activate Advanced Custom Fields plugin
  • Add New Field Group
  • Click Add Field, set
    cv_custom_url
    as value of Field Label and Field Name
  • In Location box, “Show this field group if” heading,
    select Attachment for first select-box, All for the third select-box.
  • Update or Publish the Field Group
  • Finally, edit each media file, then set your custom URL as value of cv_custom_url field.

# Keep The Original Link (To The Post Page)

By adding the cv_custom_url custom field to a post, elements (title, thumbnail, read-more button) of the post in View will link to the custom/external URL.
To keep original link (to the post page) for any elements, please add this code to file functions.php in the theme’s folder:

// Content Views Pro - Keep the original URL
add_filter( 'pt_cv_field_href', 'cvp_theme_keep_post_url', 9999, 2 );
function cvp_theme_keep_post_url( $href, $post ) {
	$traces = debug_backtrace( 2 );

	$keep_post_url = array();

	// Remove # below to keep original URL for Title
	# $keep_post_url[] = '_field_title';
	
	// Remove # below to keep original URL for Thumbnail
	# $keep_post_url[] = '_field_thumbnail';
	
	// Remove # below to keep original URL for "Read more" button
	# $keep_post_url[] = '_field_content';

	foreach ( $traces as $trace ) {
		if ( in_array( $trace[ 'function' ], $keep_post_url ) ) {
			$href = get_permalink( $post );
		}
	}

	return $href;
}

If you already used the “WP Gallery Custom Links” plugin to set custom link, you can integrate it with Content Views by adding this code to file functions.php in the theme’s folder:

// Content Views Pro - use custom link by "WP Gallery Custom Links" plugin
add_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_wpgallerycustomlink', 100, 2 );
function cvp_theme_use_custom_url_by_wpgallerycustomlink( $href, $post ) {
	$custom_url = get_post_meta( $post->ID, '_gallery_link_url', true );
	if ( $custom_url ) {
		$href = $custom_url;
	}

	return $href;
}

# Use custom link by the “Page Links To” plugin

If you already used the “Page Links To” plugin to set custom link, you can integrate it with Content Views by adding this code to file functions.php in the theme’s folder:

// Content Views Pro - use custom link by "Page Links To" plugin
add_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_pagelinksto', 100, 2 );
function cvp_theme_use_custom_url_by_pagelinksto( $href, $post ) {
	$custom_url = get_post_meta( $post->ID, '_links_to', true );
	if ( $custom_url ) {
		$href = $custom_url;
	}

	return $href;
}

Best regards,