JReviews logo
Guides My site
← All guides Community guide

Remove links from listing descriptions

CMoore Alejandro
Thread started by CMoore. Contributors Alejandro.
Thread started
Last updated

What you’ll achieve

Remove clickable links from listing detail descriptions while keeping the linked text and saved descriptions.

My site

Platform
JReviews version

Keep visitors on your site by removing clickable links from listing detail descriptions while keeping the linked text. Use dedicated Website fields for the external links you allow. The callback leaves saved content and list-page output unchanged.

Only the displayed description changes. The code removes ordinary links only. It does not make all submitted HTML safe or remove every unwanted HTML element.

The legacy page can display the summary and description together. This code removes links from both parts of that combined text. The code removes ordinary links only. It does not make all submitted HTML safe or remove every unwanted HTML element.

If the requirement is to prevent HTML at submission, review the site's HTML permissions instead of treating this display filter as input validation.

Start a new PHP file with <?php followed by defined('MVC_FRAMEWORK') or die;. If the file already exists, add the example without repeating those lines.

Add the filter

Joomla. Use templates/jreviews_overrides/hooks.php.

WordPress. Use jreviews_overrides/hooks.php.

Enable Listing Detail Page in Early Access. Add the callback marked with +. It changes a copy of the description used on the detail page. Other uses of the original description remain unchanged.

  • If hooks.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating hooks.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

fwd_add_filter('jreviews:view_data:listings_detail', function ($data, $normalizedName, $originalName) {
    if (!isset($data['listing'])) {
        return $data;
    }
    $listing = clone $data['listing'];
    $listing->description = preg_replace('#<a\b[^>]*>(.*?)</a>#is', '$1', (string) $listing->description);
    $data['listing'] = $listing;
    return $data;
}, 20, 3);

Add the filter

Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Add the function and filter marked with +. They use post_get_listing_detailpage_query to change the listing description before the detail theme receives it. This avoids editing the detail theme just to remove ordinary HTML links.

  • If filter_functions.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating filter_functions.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

function strip_links_detail($listing, $params)
{
    $listing['Listing']['text'] = preg_replace('#<a\b[^>]*>(.*?)</a>#is', '$1', $listing['Listing']['text']);

    return $listing;
}

Clickfwd\Hook\Filter::add('post_get_listing_detailpage_query', 'strip_links_detail', 10);

Visitors see the text that was inside each link, but they can no longer click it. The detail page changes without rewriting the saved description.

This regular expression handles the simple anchor markup shown in the example. It is not an HTML sanitizer and does not guarantee removal of malformed or other unusual markup. Keep your normal HTML validation and filtering in place.

Test ordinary links, multiple links, and text without links. Confirm the detail page keeps the linked text but removes its clickable wrapper, and that the stored description remains unchanged. This example handles ordinary HTML links. Broken or unusual link HTML needs a separate solution; keep your normal HTML validation and filtering enabled.

Learn more