Skip to content

Rendering & Template HTML Filters ​

These filters return HTML. Override them to replace a whole template block — as opposed to a single element, which uses action hooks.

wpsocialreviews/add_reviews_template ​

wpsocialreviews/add_reviews_template — The rendered reviews HTML

When it runs: Applied when a reviews template is rendered, wrapping the generated markup. Return modified HTML to change the output, or inspect the reviews/meta to append your own.

Parameters:

  • $template (string): the generated HTML.
  • $reviews (array): the reviews being rendered.
  • $meta (array): the template meta.
  • $business_info (array): business info for the source(s).

Source: app/Hooks/Handlers/ShortcodeHandler.php, ReviewsTemplateHandler.php

Usage:

php
add_filter('wpsocialreviews/add_reviews_template', function ($template, $reviews, $meta, $business_info) {
    if (empty($reviews)) {
        return $template;
    }
    return $template . '<p class="wpsr-note">Verified reviews</p>';
}, 10, 4);

wpsocialreviews/add_instagram_feed_template ​

wpsocialreviews/add_instagram_feed_template — Instagram feed HTML for a Pro template

When it runs: Applied by core when [wp_social_ninja] renders an Instagram template whose key is a Pro template (see wpsocialreviews/instagram_pro_templates). Return the rendered markup as a string. Core checks the return type — if it is not a string, it falls back to template1, so an unfulfilled filter degrades instead of printing the word Array.

Parameters:

  • $template_body_data (array): templateId, feeds, template_meta, sinceId, maxId, image_settings, and header.

Source: app/Hooks/Handlers/ShortcodeHandler.php

Usage:

php
add_filter('wpsocialreviews/add_instagram_feed_template', function ($template_body_data) {
    if (empty($template_body_data['feeds'])) {
        return $template_body_data;
    }
    return '<div class="wpsr-ig-custom">…</div>';
});

Added in 4.4.0

Pairs with wpsocialreviews/instagram_pro_templates on the platform registry page — a template key must be advertised there and rendered here, or core will not route to it.

wpsocialreviews/render_tiktok_template ​

wpsocialreviews/render_tiktok_template — TikTok feed HTML (fulfilled by the TikTok plugin)

When it runs: Applied by core when [wp_social_ninja] renders a TikTok template (platform="tiktok"). The Custom Feed for TikTok plugin fulfills this filter to return the feed markup.

Parameters:

  • $templateId (int): the template post ID.
  • $platform (string): the platform slug.

Source: app/Hooks/Handlers/ShortcodeHandler.php

Visitor sort toolbar 4.4.0 ​

The reviews visitor toolbar (search, sort, rating filter) is printed by Pro as a sibling before the feed container, so a re-fetch that replaces the feed cannot replace the toolbar. Core owns the seam and the escaping; Pro fulfills it.

wpsocialreviews/add_reviews_sort_toolbar ​

wpsocialreviews/add_reviews_sort_toolbar — The toolbar HTML

When it runs: Applied in the reviews header view, only when Pro is active and the platform set supports visitor sorting. Return the toolbar markup as a string.

The returned HTML is passed through wp_kses() with the allowlist from Helper::sortToolbarAllowedHtml(), so anything outside that allowlist is stripped — escape as you build, and widen the allowlist with wpsocialreviews/sort_toolbar_allowed_html if you need a tag or attribute it does not carry.

Parameters:

  • $html (string): the toolbar HTML, '' by default.
  • $template_meta (array): the formatted template settings.
  • $templateId (int): the template post ID.
  • $translations (array): the template's translation strings.
  • $platforms (array): the review platform slugs this feed renders.
  • $templateType (string): the template layout, e.g. slider.

Source: app/Views/public/reviews-templates/header.php

Usage:

php
add_filter('wpsocialreviews/add_reviews_sort_toolbar', function (
    $html, $template_meta, $templateId, $translations, $platforms, $templateType
) {
    if ($html === '') {
        return $html;
    }
    return $html . '<span class="wpsr-reviews-sort-note">' . esc_html__('Sorted live', 'my-plugin') . '</span>';
}, 20, 6);

WARNING

booking.com feeds never render the toolbar: Helper::supportsVisitorSorting() excludes them because Booking stores 1–10 ratings, which the 1–5 star filter cannot describe. Your callback is not called for those feeds at all.

wpsocialreviews/reviews_sort_toolbar_enabled ​

wpsocialreviews/reviews_sort_toolbar_enabled — Whether a toolbar will render

When it runs: Asked by Helper::visitorSortToolbarEnabled() before the header view runs, so callers can adjust layout for a feed that is about to grow a toolbar. Core returns false unless Pro is active and the platforms support sorting; Pro answers with the template's own setting.

Return a boolean. Answering true does not render a toolbar — it only states that one is expected; the markup still comes from wpsocialreviews/add_reviews_sort_toolbar.

Parameters:

  • $enabled (bool): false by default.
  • $template_meta (array): the formatted template settings.
  • $templateId (int): the template post ID.
  • $templateType (string): the template layout.
  • $platforms (array): the review platform slugs.

Source: app/Services/Platforms/Reviews/Helper.php

Usage:

php
add_filter('wpsocialreviews/reviews_sort_toolbar_enabled', function (
    $enabled, $template_meta, $templateId, $templateType, $platforms
) {
    if ($templateType === 'slider') {
        return false; // no toolbar on sliders
    }
    return $enabled;
}, 10, 5);

wpsocialreviews/sort_toolbar_allowed_html ​

wpsocialreviews/sort_toolbar_allowed_html — The wp_kses() allowlist for the toolbar

When it runs: Applied when the reviews header builds the wp_kses() allowlist for the toolbar HTML. Return the modified array.

The default allowlist covers the toolbar's own contract: form, label, span, input, select, option, and inline svg / circle / path, plus the data-template_id, data-order, data-rating, data-search, data-product_id and data-seed attributes the toolbar JS reads back.

Parameters:

  • $allowed (array): the wp_kses() allowlist, keyed by tag.

Source: app/Services/Platforms/Reviews/Helper.php

Usage:

php
add_filter('wpsocialreviews/sort_toolbar_allowed_html', function ($allowed) {
    $allowed['button'] = [
        'class'      => [],
        'type'       => [],
        'aria-label' => [],
    ];
    return $allowed;
});

DANGER

This allowlist is the last boundary on markup that reaches the page from a filter. Widen it with specific tags and attributes; never return a permissive array such as wp_kses_allowed_html('post') plus arbitrary attributes.

wpsocialreviews/frontend_review_sort_options Pro ​

wpsocialreviews/frontend_review_sort_options — Which sort options a visitor sees

When it runs: Applied by Pro when building the toolbar's sort <select>. Return a key => label array.

The filter governs what a visitor is offered, never what the query honours — Pro validates every returned key against its canonical sort map and drops anything unrecognised, along with non-string keys, non-scalar labels, and empty labels. A non-array return yields no options at all.

Parameters:

  • $defaults (array): newest, oldest, rating_desc, rating_asc mapped to translated labels.
  • $templateId (int): the template post ID.
  • $template_meta (array): the formatted template settings.

Source: Pro app/Hooks/Handlers/ReviewsTemplateHandlerPro.php

Usage:

php
add_filter('wpsocialreviews/frontend_review_sort_options', function ($options, $templateId, $template_meta) {
    unset($options['rating_asc']); // never offer "Lowest rated"
    return $options;
}, 10, 3);

Review rows & labels 4.5.0 ​

wpsocialreviews/reviews_template_rows ​

wpsocialreviews/reviews_template_rows — Split the review cards into rows

When it runs: Applied by ShortcodeHandler after the header and before the cards of a reviews template. Core renders each row in turn: it prints before, renders the card template (core grid or Pro's add_reviews_template) for that row's reviews, then prints after. The footer still receives every review, not just the last row's.

By default there is one row holding all reviews. Pro uses this filter for the Marquee layout: with 4 or more reviews it deals them into two rows that scroll in opposite directions.

Parameters:

  • $rows (array): a list of rows, each ['reviews' => array, 'before' => string, 'after' => string]. Defaults to [['reviews' => $reviews, 'before' => '', 'after' => '']].
  • $template_meta (array): the template meta. templateType holds the layout (grid, slider, marquee, …).

Source: app/Hooks/Handlers/ShortcodeHandler.php; Pro ReviewsTemplateHandlerPro::addMarqueeRows()

Usage:

php
add_filter('wpsocialreviews/reviews_template_rows', function ($rows, $template_meta) {
    if (($template_meta['templateType'] ?? '') !== 'grid' || count($rows) !== 1) {
        return $rows;
    }
    $rows[0]['before'] = '<div class="wpsr-my-row">';
    $rows[0]['after']  = '</div>';
    return $rows;
}, 20, 2);

WARNING

Core reads all three keys of every row with no fallback, so each row must have reviews, before and after. before and after are printed as they are, so escape any attribute values you put in them. Pro's Marquee callback only acts when it receives exactly one row, so a callback at priority < 10 that splits rows turns Marquee off.

wpsocialreviews/rating_quality_label ​

wpsocialreviews/rating_quality_label — The word shown for a rating

When it runs: Applied by Helper::ratingQualityLabel() (Reviews Helper), which turns a rating into one word. Pro uses it for the Score Strip and sticker badges and the Review Spotlight notification. It is not called for a rating of 0 or lower; those return '' without running the filter.

RatingDefault label
>= 4.5Excellent
>= 3.9Great
>= 2.9Average
>= 2.1Poor
below 2.1Bad

Parameters:

  • $label (string): the translated label.
  • $rating (float): the rating.

Source: app/Services/Platforms/Reviews/Helper.php

Usage:

php
add_filter('wpsocialreviews/rating_quality_label', function ($label, $rating) {
    return $rating >= 4.8 ? __('Outstanding', 'my-plugin') : $label;
}, 10, 2);

INFO

The admin badge preview (BadgeScoreStrip.vue) uses the same thresholds but does not run this PHP filter, so a changed label only shows on the front end.

wpsocialreviews/platform_display_name ​

wpsocialreviews/platform_display_name — The visible name of a review platform

When it runs: Applied by Helper::platformDisplayName() (Reviews Helper). Templates use it for the "on {source}" label, printed as the card's data-platform_label attribute and in notification "Logo + platform name" mode. It is separate from PlatformManager::getPlatformOfficialName(), which builds admin error strings.

Core has labels for google, facebook, airbnb, yelp, tripadvisor, amazon, aliexpress, booking.com, woocommerce, fluent-cart, fluent_forms, testimonial and custom. Any other slug falls back to ucfirst($platform_name). For custom, the label is the custom source's own name when it has one.

Parameters:

  • $label (string): the display name.
  • $platform_name (string): the platform slug.

Source: app/Services/Platforms/Reviews/Helper.php

Usage:

php
add_filter('wpsocialreviews/platform_display_name', function ($label, $platform_name) {
    return $platform_name === 'myplatform' ? 'My Platform' : $label;
}, 10, 2);

Other rendering / HTML filters ​

Full list — badge, notification, twitter, facebook, pagination, error messages
FilterArgsPurpose
wpsocialreviews/add_reviews_badge_templatetemplate contextReviews badge HTML
wpsocialreviews/add_reviews_notification_templatetemplate contextReviews notification HTML
wpsocialreviews/add_twitter_template$dataTwitter feed HTML
wpsocialreviews/add_facebook_feed_template$dataFacebook feed HTML
custom_feed_for_tiktok/add_tiktok_feed_template$dataTikTok feed HTML (add-on side)
wpsocialreviews/get_paginated_feed_html$templateId, $pagePaginated feed HTML
wpsr_feed_items_by_page_{platform}'', $templateId, $pagePer-platform paginated items
wpsocialreviews/after_reviews_fetch$reviews, $platformsPost-process fetched reviews
wpsocialreviews/display_frontend_error_message$platform, $error, …Front-end error markup
wpsocialreviews/reviews_schema_dataschema arrayReviews rich-snippet schema

Source: ShortcodeHandler.php, the per-platform *TemplateHandler.php files, and Views/public/reviews-templates/header.php.

WP Social Ninja Developer Documentation