• Resolved Rajat Chodhary

    (@rajatchodhary)


    Hello,
    I like the plugin. I have a suggestion which can help with template management in custom or child themes.
    One line 100, there is filter in wp-instagram-widget.php
    $template_part = apply_filters( 'wpiw_template_part', 'parts/wp-instagram-widget.php' );
    instead, change it to see inside /template-parts
    $template_part = apply_filters( 'wpiw_template_part', 'template-parts/wp-instagram-widget.php' );
    Thank you for your unselfish work,
    With best regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Scott (@scottsweb)

    (@scottsweb)

    Hi Rajat
    The filter exists so you can change it to be whatever you want. I don’t see why I would change the default if it can easily be overwritten by a filter?

    Thanks

    Scott

    Thread Starter Rajat Chodhary

    (@rajatchodhary)

    Hello Scott,

    I know that “Don’t fix unless it is broken“, and it is true.
    But, I tried to apply override filter with higher priority. But, it doesn’t work. Right now, I am using two template folder (parts and template-parts) in my theme.
    May be you may demonstrate me how to do that?

    Regards
    Rajat

    Thread Starter Rajat Chodhary

    (@rajatchodhary)

    Hello Scott,
    [Fixed]
    I figured it out. I have increased priority to 15 to make it run after default filter. Now, filter is overridden.

    For those who are visiting this ticked for a solution. I have added this line into my functions.php file and template-parts is my theme templates folders. Note: Underlying code is works fine for me. But, I, strongly, suggest you to use @scottsweb code in following reply.

    apply_filters( 'wpiw_template_part', 'template-parts/wp-instagram-widget.php', 15 );

    And, code inside template-parts/wp-instagram-widget.php is added below [I have removed alt and title from image tag].

    <?php
    // It is a WP Instagram Widget template
    echo '<li class="'. esc_attr( $liclass ) .'"><a href="'. esc_url( $item['link'] ) .'" target="'. esc_attr( $target ) .'"  class="'. esc_attr( $aclass ) .'"><img src="'. esc_url( $item[$size] ) . '"  class="'. esc_attr( $imgclass ) .'"/></a></li>';

    Regards,
    Rajat chodhary
    @wptantra

    Plugin Author Scott (@scottsweb)

    (@scottsweb)

    Hi Rajat

    That does not look right to me. The code you need is something like this:

    add_filter('wpiw_template_part', 'my_wpiw_template_part');
    
    function my_wpiw_template_part() {
        return 'template-parts/wp-instagram-widget.php';
    }

    Scott

    Thread Starter Rajat Chodhary

    (@rajatchodhary)

    Thank you @scottsweb,

    Regards,
    Rajat

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Suggestion] – Change filter to template parts’ is closed to new replies.