Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}
function osu_twentyten_auto_excerpt_more( $more ) {
 return ' &hellip;' . 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

share|improve this question
add comment

1 Answer

up vote 20 down vote accepted

You should run the code after theme setup.

function osu_twentyten_continue_reading_link() {
    return ' <a href="'. get_permalink() . '">' . __( 'Read on <span class="meta-nav">&rarr;</span>', 'twentyten-child' ) . '</a>';
}

function osu_twentyten_auto_excerpt_more( $more ) {
    return ' &hellip;' . 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' );
share|improve this answer
    
Was about to post the very same thing(or at least very similar), +1.. ;) –  t31os Jan 23 '11 at 13:39
1  
Yep. And the reason it doesn't work directly is that child theme's code is loaded before parent theme's. –  Rarst Jan 23 '11 at 14:37
    
Thanks for this, much appreciated –  Osu Jan 23 '11 at 15:47
    
Thanks a lot! A lot..........! –  user3705 Mar 4 '11 at 15:38
    
Pretty helpful - thanks! –  Banago Aug 27 '13 at 18:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.