{"id":2340,"date":"2017-10-11T05:06:42","date_gmt":"2017-10-11T05:06:42","guid":{"rendered":"http:\/\/docs.contentviewspro.com\/?p=2340"},"modified":"2023-12-29T03:39:13","modified_gmt":"2023-12-29T03:39:13","password":"","slug":"custom-text-url-custom-field","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/custom-text-url-custom-field\/","title":{"rendered":"Set link text when showing an URL custom field"},"content":{"rendered":"<p>If you are showing a custom field which has an URL string as value, for example:<\/p>\n<pre style=\"font-size:13px\">\nhttp:\/\/google.com\n<\/pre>\n<p>Content Views Pro will convert that URL string to a HTML link (anchor tag):<br \/>\n<a target=\"_blank\" href=\"http:\/\/google.com\" rel=\"noopener noreferrer\">http:\/\/google.com<\/a><\/p>\n<p>How to <strong>use a custom text for the link<\/strong>?<br \/>\nThere are 2 possible ways:<\/p>\n<p>1. Manually replace the URL string in the value of custom field by an anchor tag:<\/p>\n<pre style=\"font-size:13px\">\n&lt;a target=&quot;_blank&quot; href=&quot;http:\/\/google.com&quot;&gt;YOUR TEXT HERE&lt;\/a&gt;\n<\/pre>\n<p>2. Dynamically replace the URL string by an anchor tag using PHP code.<br \/>\nPlease add this code to file <strong>functions.php<\/strong> in the theme&#8217;s folder (or install this plugin <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" rel=\"nofollow\">Code Snippets<\/a> then add this code to <a href=\"https:\/\/ps.w.org\/code-snippets\/assets\/screenshot-2.png\" rel=\"nofollow\">the &#8220;Code&#8221; textarea<\/a>):<\/p>\n<pre style=\"font-size:13px\">\n\/\/ Content Views Pro - custom text for URL custom fields\nadd_filter( 'pt_cv_ctf_url_text', 'cvp_theme_ctf_url_text', 100, 2 );\nfunction cvp_theme_ctf_url_text( $args, $key ) {\n\tif ( $key === 'CUSTOM_FIELD_1' ) {\n\t\t$args = 'Text1';\n\t}\n\tif ( $key === 'CUSTOM_FIELD_2' ) {\n\t\t$args = 'Text2';\n\t}\n\tif ( $key === 'CUSTOM_FIELD_3' ) {\n\t\t$args = 'Text3';\n\t}\n\n\treturn $args;\n}\n<\/pre>\n<p>(replace <strong>CUSTOM_FIELD_1, CUSTOM_FIELD_2, CUSTOM_FIELD_3<\/strong> with your custom field keys. If you have only one custom field, just replace CUSTOM_FIELD_1 with your custom field key.)<\/p>\n<p>Best regards,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are showing a custom field which has an URL string as value, for example: http:\/\/google.com Content Views Pro will convert that URL string to a HTML link (anchor tag): http:\/\/google.com How to use a custom text for the link? There are 2 possible ways: 1. Manually replace the URL string in the value &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/custom-text-url-custom-field\/\"> <span class=\"screen-reader-text\">Set link text when showing an URL custom field<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"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],"doc_tag":[13,21],"class_list":["post-2340","docs","type-docs","status-publish","hentry","doc_category-custom-field","doc_tag-custom-field","doc_tag-custom-code"],"year_month":"2026-09","word_count":207,"total_views":"1","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"CVP","author_nicename":"cvp","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/cvp\/"},"doc_category_info":[{"term_name":"Custom Field (core, ACF, Metabox, etc.)","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/custom-field\/"}],"doc_tag_info":[{"term_name":"custom field","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-field\/"},{"term_name":"custom PHP code","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-code\/"}],"_links":{"self":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2340","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/comments?post=2340"}],"version-history":[{"count":2,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2340\/revisions"}],"predecessor-version":[{"id":5609,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2340\/revisions\/5609"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=2340"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=2340"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=2340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}