Hi HivePress,
I have a quick question. I created an Attribute called Website Link and the field name is website_link for simplicity to be displayed when someone is posting a listing and added to the page.
I added the words “Website: %value%” to the display and it’s working to display the URL that doesn’t look great on the Listing since everything else is pretty clean on the listing page. So, I created a Code Snippet using a number of different attempts of code to change the URL to “Click Here” that should be pretty simple, but for some reason the snippet isn’t working. Here’s the last code that I did and I’m wondering if I’m just in the wrong place for the plugin. Some of the ways I’ve tried it break the site all together, but this one doesn’t, it just doesn’t work. I’m thinking I’m just in the wrong spot within hivepress for the filter. Can you please advise?
Thank you.
add_filter('hivepress/v1/templates/listing_view_block', 'customize_website_link_in_listing', 10, 2);
function customize_website_link_in_listing($template, $listing) {
$website_link = hivepress()->get_template()->get_value($listing, 'website_link');
if ($website_link) {
// Modify the display of the website link
$template['blocks']['website_link'] = '<a href="' . esc_url($website_link) . '" target="_blank" rel="nofollow">Click Here</a>';
}
return $template;
}