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 field 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

CVPro will use this custom link for Title, Thumbnail, Read More button of post in View. To keep the original link for any of them, please check this document.


# For Media Files

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

  • Install & activate the “Advanced Custom Fields” plugin
  • From the Custom Fields admin screen, click the Add New button to create a new field group
  • Click the Add Field button, set
    cv_custom_url
    as value of Field Label and Field Name:
    acf custom url field
  • Under Location, select Attachment for first select-box:
    acf custom field for attachment
  • Click the Publish button
  • From the Media admin screen, click to edit each media file, then set your custom URL as value of cv_custom_url field:
    cvp set custom url for media

# Keep The Original Link (To The Post Page)

By adding the cv_custom_url custom field to a post, these 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,