You can use and anchor text instead of the regular long URL in the website link on the archive page/all 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 the 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/archive/fields/website.php" in your currently activated theme folder with the following code -
- <?php
- /**
- * @author wpWax
- * @since 6.6
- * @version 6.7
- */
- if ( ! defined( 'ABSPATH' ) ) exit;
- $listing_id = get_the_ID();
- $website_anchor = get_post_meta( $listing_id, '_website-anchor', true );
- $website_anchor = $website_anchor && !empty( $website_anchor ) ? $website_anchor : 'Visit Website';
- ?>
- <div class="directorist-listing-card-website"><?php directorist_icon( $icon ); ?><?php $listings->print_label( $label ); ?><a target="_blank" href="<?php echo esc_url( $value ); ?>"><?php echo esc_html( $website_anchor ); ?></a></div>
No comments:
Post a Comment