Title: Example of function implementation
Last modified: August 22, 2016

---

# Example of function implementation

 *  Resolved [tdmohr](https://wordpress.org/support/users/tdmohr/)
 * (@tdmohr)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/)
 * Hi Luke,
 * Thank-you for the great plugin. It really is exactly what I was looking for!
 * I know you don’t want to provide any support on this but I just wanted to mention
   that I am also having problems getting the filter example you posted above to
   work.
 * Displaying a testimonial via shortcode or widget simply do not appear to fire
   the ct_before_render_testimonial event. Either that or the example posted is 
   not being correctly parsed in my functions.php file. Other filters I have implemented
   are working properly though…
 * Can you please confirm that this should be working under wordpress 3.9.1?
 * I would love to properly customise the output of the testimonial without hacking
   the class.wp-testimonial.php file.
 * Thanks for any advice you can provide,
    Tim
 * [https://wordpress.org/plugins/clean-testimonials/](https://wordpress.org/plugins/clean-testimonials/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182453)
 * Hey tdmohr,
 * the `ct_before_render_testimonial` action fires immediately when the `render()`
   function runs to display a testimonial.
 * What method are you using to display the testimonial(s) on which the event is
   not firing?
 * If you aren’t using a shortcode, and instead are using a custom loop or something,
   then it won’t fire natively.
 * If you are using a custom loop, say with query_posts or get_posts and displaying
   them in succession, do `$testimonial = new WP_Testimonial( $the_post_id ); $testimonial-
   >render();`
 * If you are using a shortcode, then let me know and we can eliminate that at least.
 * Feel free to paste me a link to a gist which contains the code that isn’t working(
   or any sort of link), and I can take a look. Normally I wouldn’t ask this, but
   you seem to be more on the developer side of things than most users.
 *  Thread Starter [tdmohr](https://wordpress.org/support/users/tdmohr/)
 * (@tdmohr)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182495)
 * Hi,
 * I am using the widget and I’ve also tried the shortcode. The testimonials render
   in the same default way using both methods.
 * I think there must be something wrong with my filter implementation. Does this
   look correct to you?
 *     ```
       function render_my_testimonial ( $testimonial, $context ) {
           return '<p>' . $testimonial->post_title . '</p>';
       }
       add_filter( 'ct_before_render_testimonial', 'render_my_testimonial', 10, 2);
       ```
   
 * The function is located half way through the functions.php file but I’ve tried
   moving it around with no change. I’ve put an exit(); tag within the function 
   and the site continues loading so I believe the function render_my_testimonial
   is never called.
 * The website is currently located on my internal staging servers but if you don’t
   have any ideas I can upload to an external staging environment which might give
   you a better idea of what is going on.
 * Cheers,
    Tim
 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182506)
 * Hi Tim,
 * `ct_before_render_testimonial` is an action, not a filter. The filter I think
   you’re after is `ct_pre_render_testimonial`.
 * Try this
 *     ```
       function render_my_testimonial ( $testimonial, $context ) {
           return '<p>' . $testimonial->post_title . '</p>';
       }
       add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 2);
       ```
   
 * If `render_my_testimonial` returns anything at all, Clean Testimonials will just
   display that instead of using the default output. It is designed to override 
   the output completely.
 * Let me know how that goes.
 *  Thread Starter [tdmohr](https://wordpress.org/support/users/tdmohr/)
 * (@tdmohr)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182512)
 * Hi Luke,
 * Thanks for the reply.
 * Adding the correct filter started interupting the rendering of the plugin but
   I still didn’t see the testimonial title I was expecting. After a big of extra
   debugging I found the var $testimonial was blank and $context actually contained
   the testimonial object. I’m not sure why its not coming through the first parameter…
   perhaps you can shed some light on this…?
 * So my working code to achieve a testimonial post title is:
 *     ```
       function render_my_testimonial($testimonial, $context) {
           return '<p>' . $context->post_title . '</p>';
       }
       add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 2);
       ```
   
 * I should be good to go from here.
 * Just FYI… The code I started working from was copied from [your reply](http://wordpress.org/support/topic/example-of-function-implementation?replies=8#post-5770224)
   in the thread that I originally posted my question in…
 * Perhaps you should correct it so that others do not get confused, now that it
   has been tested.
 * Thanks for your help though, its good to not have to hack the plugin to get the
   output I need.
 * Cheers,
    Tim
 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182513)
 * Hey Tim,
 * That appears to be a bug. Can you please confirm that you are using the widget
   so we can test and fix?
 *  Thread Starter [tdmohr](https://wordpress.org/support/users/tdmohr/)
 * (@tdmohr)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182606)
 * Hi Luke,
 * Sorry for the delay.
 * The problem exists with the widget and shortcodes.
 * Thanks,
    TIm
 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182626)
 * Hi Tim,
 * Have identified a bug which will be fixed in version 1.6 very shortly. Thank 
   you for bringing this to my attention.
 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182664)
 * Have milestoned this fix for version 1.6 which will be released shortly. Look
   out for the update!
 *  Plugin Author [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * (@hellolukerollansme)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182670)
 * Hey Tim,
 * Finally had a chance to look at this. The fix was simple, the code I supplied
   you wasn’t 100%. The below will work.
 *     ```
       function render_my_testimonial( $default, $testimonial, $context ) {
       	return '<p>' . $testimonial->post_title . '</p>';
       }
       add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 3 );
       ```
   
 * Forgot about the first parameter which is passed down the filter chain. The testimonial
   object is the second parameter, with context being the third.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Example of function implementation’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/clean-testimonials_fcfcfc.svg)
 * [Clean Testimonials](https://wordpress.org/plugins/clean-testimonials/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/clean-testimonials/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/clean-testimonials/)
 * [Active Topics](https://wordpress.org/support/plugin/clean-testimonials/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/clean-testimonials/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/clean-testimonials/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [lukerollans](https://wordpress.org/support/users/hellolukerollansme/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/example-of-function-implementation-1/#post-5182670)
 * Status: resolved