{"id":66,"date":"2023-09-14T04:21:18","date_gmt":"2023-09-14T04:21:18","guid":{"rendered":"https:\/\/directorist.com\/knowledge-base\/?post_type=docs&#038;p=66"},"modified":"2023-09-14T04:21:18","modified_gmt":"2023-09-14T04:21:18","password":"","slug":"directorist-display-as-button-option-for-custom-url-field","status":"publish","type":"docs","link":"https:\/\/directorist.com\/knowledge-base\/docs\/directorist-display-as-button-option-for-custom-url-field\/","title":{"rendered":"Directorist &#8211; Display as Button option for Custom URL field"},"content":{"rendered":"\n<p>There is a way to enable the &#8220;Display as button&#8221; option for the custom URL field in the directorist builder. You can easily achieve this by implementing some custom coding and template overriding.<\/p>\n\n\n\n<p>First of all, you need to install and activate a child theme. Then, please use the following custom code in the <strong>functions.php<\/strong> file of the child theme folder. This code will enable a new field to enable the &#8220;Display as button&#8221; option and enter the &#8220;Anchor Text&#8221; in the Directory builder.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"414\" src=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image.png\" alt=\"\" class=\"wp-image-68\" srcset=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image.png 567w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-300x219.png 300w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-360x263.png 360w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('atbdp_single_listing_content_widgets', function ($widgets) {\n\t$widgets&#091;'url']&#091;'options']&#091;'display_button'] =\n\t\t&#091;\n\t\t\t'type'  =&gt; 'toggle',\n\t\t\t'label' =&gt; __('Display as button', 'directorist'),\n\t\t\t'value' =&gt; '',\n\t\t];\n\t$widgets&#091;'url']&#091;'options']&#091;'anchor'] = &#091;\n\t\t'type' =&gt; 'text',\n\t\t'label' =&gt; __('Anchor Text', 'directorist'),\n\t\t'value' =&gt; 'Visit',\n\t\t'show_if' =&gt; &#091;\n\t\t\t'where' =&gt; \"self.display_button\",\n\t\t\t'conditions' =&gt; &#091;\n\t\t\t\t&#091;'key' =&gt; 'value', 'compare' =&gt; '=', 'value' =&gt; true],\n\t\t\t],\n\t\t],\n\t];\n\treturn $widgets;\n});<\/code><\/pre>\n\n\n\n<p>Now, you need to override the template. <\/p>\n\n\n\n<p>Please read the template override documentation before you start this process. This will help you to understand how to override the templates properly.<\/p>\n\n\n\n<p><a href=\"https:\/\/directorist.com\/documentation\/directorist\/developers-guide\/template-override\/\">Template Override (directorist.com)<\/a><\/p>\n\n\n\n<p>Please create a file&nbsp;<strong>&#8220;directorist\/single\/custom-fields\/url.php&#8221;<\/strong>&nbsp;in your currently activated theme folder with the following code<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"558\" src=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/08\/image-2.png\" alt=\"\" class=\"wp-image-53\" srcset=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/08\/image-2.png 638w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/08\/image-2-300x262.png 300w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/08\/image-2-360x315.png 360w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n\/**\n * @author  wpWax\n * @since   6.7\n * @version 7.0.5.2\n *\/\n\nif (!defined('ABSPATH')) exit;\n$display_button = isset($data&#091;'display_button']) &amp;&amp; !empty($data&#091;'display_button']) ? $data&#091;'display_button'] : false;\n$anchor_text = isset($data&#091;'anchor']) &amp;&amp; !empty($data&#091;'anchor']) ? $data&#091;'anchor'] : 'Visit';\n?&gt;\n\n&lt;div class=\"directorist-single-info directorist-single-info-url\"&gt;\n\n    &lt;?php if ($display_button) : ?&gt;\n        &lt;div class=\"directorist-single-info__value\"&gt;&lt;a class=\"directorist-btn directorist-btn-primary url-btn-style\" target=\"_blank\" href=\"&lt;?php echo esc_url($value); ?&gt;\" &lt;?php echo !empty($data&#091;'use_nofollow']) ? 'rel=\"nofollow\"' : ''; ?&gt;&gt;&lt;?php echo esc_html($anchor_text); ?&gt;&lt;\/a&gt;&lt;\/div&gt;\n    &lt;?php else : ?&gt;\n        &lt;div class=\"directorist-single-info__label\"&gt;\n            &lt;span class=\"directorist-single-info__label-icon\"&gt;&lt;?php directorist_icon($icon); ?&gt;&lt;\/span&gt;\n            &lt;span class=\"directorist-single-info__label--text\"&gt;&lt;?php echo esc_html($data&#091;'label']); ?&gt;&lt;\/span&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"directorist-single-info__value\"&gt;&lt;a target=\"_blank\" href=\"&lt;?php echo esc_url($value); ?&gt;\" &lt;?php echo !empty($data&#091;'use_nofollow']) ? 'rel=\"nofollow\"' : ''; ?&gt;&gt;&lt;?php echo esc_html($value); ?&gt;&lt;\/a&gt;&lt;\/div&gt;\n    &lt;?php endif; ?&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>Overriding this template will do the job for you. Now you will be able to see the button with the provided anchor text on the single listing page.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"468\" height=\"317\" src=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-1.png\" alt=\"\" class=\"wp-image-69\" srcset=\"https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-1.png 468w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-1-300x203.png 300w, https:\/\/directorist.com\/knowledge-base\/wp-content\/uploads\/sites\/7\/2023\/09\/image-1-360x244.png 360w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/figure>\n\n\n\n<p>Now, you can design the button with custom CSS. It is really easy to change CSS code using this class &#8220;url-btn-style&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.url-btn-style{color: #fff}<\/code><\/pre>\n\n\n\n<p>Please contact us if you need help with any issue related to this custom coding &#8211; support@directorist.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a way to enable the &#8220;Display as button&#8221; option for the custom URL field in the directorist builder. You can easily achieve this by implementing some custom coding and template overriding. First of all, you need to install and activate a child theme. Then, please use the following custom code in the functions.php [&hellip;]<\/p>\n","protected":false},"author":4606,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[3],"doc_tag":[],"knowledge_base":[],"class_list":["post-66","docs","type-docs","status-publish","hentry","doc_category-custom-code"],"year_month":"2026-04","word_count":471,"total_views":"1915","reactions":{"happy":"0","normal":"0","sad":"1"},"author_info":{"name":"Mahfuzul Alam","author_nicename":"mahfuz","author_url":"https:\/\/directorist.com\/knowledge-base\/author\/mahfuz\/"},"doc_category_info":[{"term_name":"Custom Code","term_url":"https:\/\/directorist.com\/knowledge-base\/home\/non-knowledgebase\/custom-code\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/docs\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/users\/4606"}],"replies":[{"embeddable":true,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/docs\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/doc_category?post=66"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/doc_tag?post=66"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/directorist.com\/knowledge-base\/wp-json\/wp\/v2\/knowledge_base?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}