Home>Support>Template file filter

Template file filter

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi! I’am trying to replace basic sow-testimonials widget themplate by this gide – Template file filter, but nothing work, what i do wrong?

this code i put into functions.php in child theme:

function mytheme_testimonials_template_file( $filename, $instance, $widget ){
    if( !empty($instance['design']['theme']) && $instance['design']['theme'] == 'test' ) {
		
		 // This option works for plugins
        $filename = plugin_dir_path( __FILE__ ) . 'tpl/default.php';
		
        // And this one for themes
        $filename = get_stylesheet_directory() . '/tpl/1.php'; // this modify copy of original default.php in widget dirrectory
    }
    return $filename;
}
add_filter( 'siteorigin_widgets_template_file_sow-testimonials', 'mytheme_testimonials_template_file', 10, 3 );

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 7 years, 8 months ago Alex S
    Hi, I Work Here

    Hi Constantin,

    The provided code requires that the test Testimonials theme is being used. Can you please send me the code you’re using where you added that theme?

    If you haven’t done that yet, this is possible by modifying the form.

  2. 7 years, 8 months ago Constantin Kriptonitov

    Alex, thanks a lot! I missing this part, but now this works fine! This is how i am modified button example to use width testimonials widget:

    //custom testimonials template
    function mytheme_extend_testimonials_form( $form_options, $widget ){
        // Lets add a new layout option
        if( !empty($form_options['design']['fields']['layout']['options']) ) {
            $form_options['design']['fields']['layout']['options']['test'] = __('Test Style', 'mytheme');
        }
    
        return $form_options;
    }
    add_filter('siteorigin_widgets_form_options_sow-testimonials', 'mytheme_extend_testimonials_form', 10, 2);
    
    function mytheme_testimonials_template_file( $filename, $instance, $widget ){
        if( !empty($instance['design']['layout']) && $instance['design']['layout'] == 'test' ) {
    
            // And this one for themes
            $filename = get_stylesheet_directory() . '/tpl/1.php';  // this modify copy of original default.php in widget dirrectory
        }
        return $filename;
    }
    add_filter( 'siteorigin_widgets_template_file_sow-testimonials', 'mytheme_testimonials_template_file', 10, 3 );
    

    Now i can choose my own template in widget front-end editor!

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More