How can you wrap add_filter with a if is_home() statement?
Question
I have the follow code:
if ( !function_exists( 'df_excerpt_more' ) ) {
function df_excerpt_more( $more ) {
return ' … <a class="more-link" href="' . esc_url( get_permalink( get_the_ID() ) ) . '">' . esc_attr__( 'Read More', 'applique' ) . '<i class="ion-ios-arrow-thin-right"></i></a>';
}
add_filter( 'excerpt_more', 'df_excerpt_more' );
}
I’d like to add a second line of “add_filter” and execute it only if page is home. So I’m trying this:
if ( !function_exists( 'df_excerpt_more' ) ) {
function df_excerpt_more( $more ) {
return ' … <a class="more-link" href="' . esc_url( get_permalink( get_the_ID() ) ) . '">' . esc_attr__( 'Read More', 'applique' ) . '<i class="ion-ios-arrow-thin-right"></i></a>';
}
add_filter( 'excerpt_more', 'df_excerpt_more' );
//second filter if is home like this:
if ( is_home() ) :
add_filter('get_the_excerpt', 'df_excerpt_more');
endif;
}
For some reason this isn’t working. Seems like something very simple. What am I missing?
0
filters, page-specific-settings
4 years
2020-05-18T15:10:47-05:00
2020-05-18T15:10:47-05:00 0 Answers
91 views
0
Leave an answer