{"id":257,"date":"2015-07-26T08:43:36","date_gmt":"2015-07-26T08:43:36","guid":{"rendered":"http:\/\/docs.contentviewspro.com\/?p=257"},"modified":"2024-09-25T09:23:19","modified_gmt":"2024-09-25T09:23:19","password":"","slug":"link-to-external-custom-url","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/link-to-external-custom-url\/","title":{"rendered":"Use custom\/external URL for grid items"},"content":{"rendered":"\n<blockquote><p>This feature is only available in the <a href=\"https:\/\/www.contentviewspro.com\/#buynow\" target=\"_blank\" rel=\"noopener noreferrer\">Pro version<\/a>.<\/p><\/blockquote>\n\n\n<p>To use a custom URL for posts in our grid\/list, you only need to <strong>create a custom field for the post<\/strong>, with field name is <strong>cv_custom_url<\/strong>, and value is the custom URL you want to use:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-258\" src=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/add-custom-field.png\" alt=\"add-custom-field\" width=\"837\" height=\"229\" srcset=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/add-custom-field.png 837w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/add-custom-field-300x82.png 300w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/add-custom-field-768x210.png 768w\" sizes=\"auto, (max-width: 837px) 100vw, 837px\" \/><\/p>\n<p>(<a href=\"http:\/\/contentviewspro.com\/documentation\/article\/add-new-custom-field-wordpress-post\/\" target=\"_blank\" rel=\"noopener noreferrer\">read more about adding a custom field<\/a>)<\/p>\n<p>That is simple.<\/p>\n<p>For some advanced cases, please check below sections.<\/p>\n<hr \/>\n<h2 id=\"for_media\"># For Media Files<\/h2>\n<p>If you are selecting the <strong>Media<\/strong> option in Filter Settings &gt; Content Type, and want to add custom URL for media files, please follow following steps:<\/p>\n<ul>\n<li>Install &amp; activate the <a href=\"https:\/\/wordpress.org\/plugins\/advanced-custom-fields\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">&#8220;Advanced Custom Fields&#8221; plugin<\/a><\/li>\n<li>From the <strong>Custom Fields<\/strong> admin screen, click the <strong>Add New<\/strong> button to create a new field group<\/li>\n<li>Click the <strong>Add Field<\/strong> button, set<br \/>\n<code>cv_custom_url<\/code><br \/>\nas value of <strong>Field Label<\/strong> and <strong>Field Name<\/strong>:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3096\" src=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-url-field.png\" alt=\"acf custom url field\" width=\"864\" height=\"333\" srcset=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-url-field.png 864w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-url-field-300x116.png 300w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-url-field-768x296.png 768w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/li>\n<li>Under Location, select <code>Attachment<\/code> for first select-box:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3095\" src=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-field-for-attachment.png\" alt=\"acf custom field for attachment\" width=\"857\" height=\"216\" srcset=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-field-for-attachment.png 857w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-field-for-attachment-300x76.png 300w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/acf-custom-field-for-attachment-768x194.png 768w\" sizes=\"auto, (max-width: 857px) 100vw, 857px\" \/><\/li>\n<li>Click the <strong>Publish<\/strong> button<\/li>\n<li>From the <strong>Media<\/strong> admin screen, click to edit each media file, then set your custom URL as value of <code>cv_custom_url<\/code> field:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3097\" src=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/cvp-set-custom-url-for-media.png\" alt=\"cvp set custom url for media\" width=\"548\" height=\"583\" srcset=\"https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/cvp-set-custom-url-for-media.png 548w, https:\/\/contentviewspro.com\/documentation\/wp-content\/uploads\/2015\/07\/cvp-set-custom-url-for-media-282x300.png 282w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/li>\n<\/ul>\n<h2 id=\"original\"># Keep The Original Link (To The Post Page)<\/h2>\n<p>By adding the <code>cv_custom_url<\/code> custom field to a post, these elements:<\/p>\n<ul>\n<li>title<\/li>\n<li>thumbnail<\/li>\n<li>read-more button<\/li>\n<\/ul>\n<p>of the post in View will link to the custom\/external URL.<\/p>\n<p>To keep original link (to the post page) for any elements, please add this code to file <strong>functions.php<\/strong> in the theme&#8217;s folder:<\/p>\n<pre style=\"font-size: 13px;\">\/\/ Content Views Pro - Keep the original URL\nadd_filter( 'pt_cv_field_href', 'cvp_theme_keep_post_url', 9999, 2 );\nfunction cvp_theme_keep_post_url( $href, $post ) {\n\t$traces = debug_backtrace( 2 );\n\n\t$keep_post_url = array();\n\n\t\/\/ Remove below # to keep original URL for Title\n\t# $keep_post_url[] = '_field_title';\n\t\n\t\/\/ Remove below # to keep original URL for Thumbnail\n\t# $keep_post_url[] = '_field_thumbnail';\n\t\n\t\/\/ Remove below # to keep original URL for \"Read more\" button\n\t# $keep_post_url[] = '_field_content';\n\n\tforeach ( $traces as $trace ) {\n\t\tif ( in_array( $trace[ 'function' ], $keep_post_url ) ) {\n\t\t\t$href = get_permalink( $post );\n\t\t}\n\t}\n\n\treturn $href;\n}\n<\/pre>\n<h2 id=\"customfield\"># Use another custom field as custom link<\/h2>\n<p>If you set the link using another custom field, you can use that custom link by adding this code to file <strong>functions.php<\/strong> in the theme&#8217;s folder:<\/p>\n<pre style=\"font-size: 13px;\">\/\/ Content Views Pro - use custom field value as custom link\nadd_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_customfield', 100, 2 );\nfunction cvp_theme_use_custom_url_by_customfield( $href, $post ) {\n\t$custom_url = get_post_meta( $post-&gt;ID, 'CUSTOM_FIELD_HERE', true );\n\tif ( $custom_url ) {\n\t\t$href = $custom_url;\n\t}\n\n\treturn $href;\n}\n<\/pre>\n<p>If you set custom link by the &#8220;<strong>WP Gallery Custom Links<\/strong>&#8221; plugin, replaced <code>CUSTOM_FIELD_HERE<\/code> by <code>_gallery_link_url<\/code>.<\/p>\n<p>If you set custom link by the &#8220;<strong>Page Links To<\/strong>&#8221; plugin, replaced <code>CUSTOM_FIELD_HERE<\/code> by <code>_links_to<\/code>.<\/p>\n<p>Otherwise, replace <code>CUSTOM_FIELD_HERE<\/code> with the name\/key of the custom field.<\/p>\n<h2 id=\"shortcode\"># Use shortcode as value of &#8220;cv_custom_url&#8221;<\/h2>\n<p>If the value of the &#8220;cv_custom_url&#8221; field is not an URL, but an shortcode, please this code to file <strong>functions.php<\/strong> in the theme&#8217;s folder:<\/p>\n<pre style=\"font-size: 13px;\">\/\/ Content Views Pro - use shortcode as custom link\nadd_filter( 'pt_cv_field_href', 'cvp_theme_use_custom_url_by_customfield_sc', 999, 2 );\nfunction cvp_theme_use_custom_url_by_customfield_sc( $href, $post ) {\n\t$custom_url = get_post_meta( $post-&gt;ID, 'cv_custom_url', true );\n\tif ( $custom_url ) {\n\t\t$href = do_shortcode( $custom_url );\n\t}\n\n\treturn $href;\n}\n<\/pre>\n<p>Best regards,<\/p>","protected":false},"excerpt":{"rendered":"<p>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: (read more about adding a custom field) That is simple. &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/link-to-external-custom-url\/\"> <span class=\"screen-reader-text\">Use custom\/external URL for grid items<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"doc_category":[52,45],"doc_tag":[15],"class_list":["post-257","docs","type-docs","status-publish","hentry","doc_category-custom-field","doc_category-popular-features","doc_tag-post-title"],"year_month":"2026-09","word_count":559,"total_views":"3","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"admin1","author_nicename":"admin1","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/admin1\/"},"doc_category_info":[{"term_name":"Custom Field (core, ACF, Metabox, etc.)","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/custom-field\/"},{"term_name":"Popular Features","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/popular-features\/"}],"doc_tag_info":[{"term_name":"post title","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/post-title\/"}],"_links":{"self":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":10,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/257\/revisions"}],"predecessor-version":[{"id":5972,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/257\/revisions\/5972"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=257"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}