I’ve been reading around and trying to figure out how to do this, but for some reason I can’t seem to override parent functions in my child theme.
I’m using TwentyTen as a parent – can anyone tell me why this function in my child theme isn’t overriding the parent function please?
// Override read more link
function osu_twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . osu_twentyten_continue_reading_link();
}
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
I thought you had to remove the filter/action etc. before re-adding it right?
Thanks,
osu
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You should run the code after theme setup.
function osu_twentyten_continue_reading_link() {
return ' <a href="'. get_permalink() . '" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">' . __( 'Read on <span class="meta-nav">→</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
return ' …' . osu_twentyten_continue_reading_link();
}
function my_child_theme_setup() {
remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_twentyten_auto_excerpt_more' );
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0