This feature is only available in the Pro version.

To use a custom URL for posts in our grid/list, you only need to create a custom field for the post, with field name is cv_custom_url, and value is the custom URL you want to use:

add-custom-field

(read more about adding a custom field)

That is simple.

For some advanced cases, please check below sections.


# For Media Files

If you are selecting the Media option in Filter Settings > Content Type, and 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;
}

# Use another custom field as custom link

If you set the link using another custom field, you can use that custom link by adding this code to file functions.php in the theme’s folder:

// Content Views Pro - use custom field value as custom link
add_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_customfield', 100, 2 );
function cvp_theme_use_custom_url_by_customfield( $href, $post ) {
	$custom_url = get_post_meta( $post->ID, 'CUSTOM_FIELD_HERE', true );
	if ( $custom_url ) {
		$href = $custom_url;
	}

	return $href;
}

If you set custom link by the “WP Gallery Custom Links” plugin, replaced CUSTOM_FIELD_HERE by _gallery_link_url.

If you set custom link by the “Page Links To” plugin, replaced CUSTOM_FIELD_HERE by _links_to.

Otherwise, replace CUSTOM_FIELD_HERE with the name/key of the custom field.

# Use shortcode as value of “cv_custom_url”

If the value of the “cv_custom_url” field is not an URL, but an shortcode, please this code to file functions.php in the theme’s folder:

// Content Views Pro - use shortcode as custom link
add_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_customfield_sc', 999, 2 );
function cvp_theme_use_custom_url_by_customfield_sc( $href, $post ) {
	$custom_url = get_post_meta( $post->ID, 'cv_custom_url', true );
	if ( $custom_url ) {
		$href = do_shortcode( $custom_url );
	}

	return $href;
}

Best regards,

Scroll to Top