Hooks: Actions and Filters
Extend Real Testimonials with code — a set of filter hooks for developers who want to change behavior beyond the settings screens.
Real Testimonials ships with filter hooks you can use to tweak how the plugin behaves. A filter hook is a spot in the code where WordPress lets you step in and change a value before it's used — you "hook" your own function onto it.
To use any of these, add the snippet to your theme's functions.php file. It's best to put it in a child theme's functions.php rather than the parent theme's — that way a theme update won't wipe out your customizations.
For developers
This page assumes you're comfortable editing PHP. A mistake in functions.php can take your site down, so test on staging first and keep a backup.
Jump to a hook:
- Grant Editors access to the plugin
- Remove a Safe Web Font
- Add custom fonts
- Load the testimonial styles in the header
- Change the "No testimonials found" text
- Fix the WPML translation issue
- Change the "End of content" text
- Add custom social profile icons
- Add custom Google Fonts to Typography
1. Grant Editors access to the plugin
By default only Administrators can manage the plugin. To let Editors in too, hook onto sp_real_testimonial_ui_permission and return a capability that Editors have (like edit_others_posts).
// Plugin access to editors
function sp_real_testimonial_ui_permission_editor() {
return 'edit_others_posts';
}
add_filter( 'sp_real_testimonial_ui_permission', 'sp_real_testimonial_ui_permission_editor' );2. Remove a Safe Web Font
Don't want a particular Safe Web Font cluttering the Typography section? Filter spftestimonial_field_typography_safewebfonts and unset() the font by its array key.
function typography_safewebfonts_remove( $safewebfonts ) {
unset( $safewebfonts['0'] ); // Removes the Arial font
return $safewebfonts;
}
add_filter( 'spftestimonial_field_typography_safewebfonts', 'typography_safewebfonts_remove' );3. Add custom fonts
To offer your own fonts in the plugin, filter spftestimonial_field_typography_customwebfonts and return the font names. The fonts must already be enqueued/loaded by your theme or site — this only adds them to the picker.
function sp_custom_fonts() {
$custom_fonts = array(
'Jupiter SP',
'Sonar Bangla',
'Ruposhi Bangla',
);
return $custom_fonts;
}
add_filter( 'spftestimonial_field_typography_customwebfonts', 'sp_custom_fonts' );4. Load the testimonial styles in the header
By default the plugin's CSS loads in the footer. To load it in the <head> instead, return true on sp_testimonial_style_load_in_header.
add_filter( 'sp_testimonial_style_load_in_header', '__return_true' );5. Change the "No testimonials found" text
When a View has no testimonials to show, the plugin prints "No testimonials found." Change that wording with sptpro_not_found_any_testimonial.
function sptpro_not_found_text() {
return __( 'Sorry, no testimonials found', 'testimonial-pro' );
}
add_filter( 'sptpro_not_found_any_testimonial', 'sptpro_not_found_text' );6. Fix the WPML translation issue
If testimonials translated with WPML don't display correctly on the front end, stop the plugin from suppressing query filters by returning false on spt_testimonial_pro_suppress_filters.
add_filter( 'spt_testimonial_pro_suppress_filters', '__return_false' );7. Change the "End of content" text
With pagination, once every testimonial has loaded the plugin shows "End of content." Rename it with sp_testimonial_pro_pagination_end_content_text.
function sp_testimonial_pro_pagination_end_content_text_modified() {
return __( 'No more testimonials', 'testimonial-pro' );
}
add_filter( 'sp_testimonial_pro_pagination_end_content_text', 'sp_testimonial_pro_pagination_end_content_text_modified' );8. Add custom social profile icons
To add your own options to the reviewer Social Profile list, filter sp_testimonial_social_profile_list and return an array of icons. Each entry needs a name and an icon (a Font Awesome markup string). The example below adds Email and Download.
function sp_testimonial_social_profile_list_custom() {
$custom_icon_list = array(
'email' => array(
'name' => esc_html__( 'Email', 'testimonial-pro' ),
'icon' => '<i class="fa fa-envelope"></i>',
),
'download' => array(
'name' => esc_html__( 'Download', 'testimonial-pro' ),
'icon' => '<i class="fa fa-download"></i>',
),
);
return $custom_icon_list;
}
add_filter( 'sp_testimonial_social_profile_list', 'sp_testimonial_social_profile_list_custom' );9. Add custom Google Fonts to Typography
Similar to #3, but for Google Fonts: filter spftestimonial_field_typography_googlewebfonts and return the font names. Again, the fonts must already be enqueued/loaded by your theme or site.
function sp_custom_google_fonts() {
$webfonts = array(
'Jupiter SP',
'Sonar Bangla',
'Ruposhi Bangla',
);
return $webfonts;
}
add_filter( 'spftestimonial_field_typography_googlewebfonts', 'sp_custom_google_fonts' );