You can use and anchor text instead of the regular long URL in the website link on the single listing page by using some custom code.
Please follow the procedure to achieve this functionality on your website with the Directorist.
1. Enabling the key field:
Please copy and paste the following code at the end of the "functions.php" file of the currently activated theme folder.
- add_filter('directorist_custom_field_meta_key_field_args', function ($args) {
- $args['type'] = 'text';
- return $args;
- });
2. Create a custom text field below the website field:
Please create a new custom text field below the website field on the add listing form layout at Directory Builder section like below. Please make sure you name the key "website-anchor" like the following image -
3. Template Override:
Please read the template override documentation before you start this process. This will help you to understand how to override the templates properly.
Template Override Documentation
Please create a file "directorist/single/fields/website.php" in your currently activated theme folder with the following code -
- <?php
- /**
- * @author wpWax
- * @since 6.7
- * @version 7.0.5.2
- */
- if ( ! defined( 'ABSPATH' ) ) exit;
- $website_anchor = get_post_meta( $data['listing_id'], '_website-anchor', true );
- $website_anchor = $website_anchor && !empty( $website_anchor ) ? $website_anchor : 'Visit Website';
- ?>
- <div class="directorist-single-info directorist-single-info-web">
- <div class="directorist-single-info__label">
- <span class="directorist-single-info__label-icon"><?php directorist_icon( $icon );?></span>
- <span class="directorist-single-info__label--text"><?php echo esc_html( $data['label'] ); ?></span>
- </div>
- <div class="directorist-single-info__value">
- <a target="_blank" href="<?php echo esc_url( $value ); ?>"<?php echo !empty( $data['use_nofollow'] ) ? 'rel="nofollow"' : ''; ?>><?php echo esc_html( $website_anchor ); ?></a>
- </div>
- </div>
No comments:
Post a Comment