Why can't I override WP's 'excerpt_more' filter via my child theme functions? Why can't I override WP's 'excerpt_more' filter via my child theme functions? wordpress wordpress

Why can't I override WP's 'excerpt_more' filter via my child theme functions?


Ok, so after much frustration, I found a solution to this (I thought Child Themes were meant to speed things up!?). I believe this works because 'after_theme_setup' is run once the parent theme has been set up meaning you can remove / override Twenty Eleven's functions at that point.

If I've understood correctly, according to this documentation, the Child Theme is run first, then the parent and then the 'after_theme_setup' bit of code in your Child Theme's functions.php file:

http://codex.wordpress.org/Child_Themes#Using_functions.php

and

http://codex.wordpress.org/Plugin_API/Action_Reference/after_setup_theme

This is what's in my Child Theme's functions.php file, hope this helps someone:

// ------------------------------------------------------------------//                      // !AFTER_SETUP_THEME// ------------------------------------------------------------------/* Set up actions */add_action( 'after_setup_theme', 'osu_setup' );if ( ! function_exists( 'osu_setup' ) ):function osu_setup() {    // OVERRIDE : SIDEBAR GENERATION FUNCTION - NO WIDGETS FOR THIS SITE    remove_action( 'widgets_init', 'twentyeleven_widgets_init' ); /* Deregister sidebar in parent */    // OVERRIDE : EXCERPT READ MORE LINK FUNCTION    function osu_readon_link() {        return '...<a href="'. get_permalink() . '" class="readmore">' . __( 'Read More...', 'clientname' ) . '</a>';    }    // Function to override    function osu_clientname_custom_excerpt_more( $output ) {        if ( has_excerpt() && ! is_attachment() ) {            // $output = trim($output);            $output .= osu_readon_link();        }        return $output;    }    remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );    add_filter( 'get_the_excerpt', 'osu_clientname_custom_excerpt_more' );    remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );    add_filter( 'excerpt_more', 'osu_readon_link' );    // OVERRIDE : EXCERPT LENGTH FUNCTION    function osu_clientname_excerpt_length( $length ) {        return 30;    }    remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );    add_filter( 'excerpt_length', 'osu_clientname_excerpt_length' );}endif; // osu_setup


Your own answer is complicating things and really shouldn't be necessary. I couldn't explain the why of my answers, because I found it in another answer. But in any case you can ALWAYS override functions from the parent theme in your child theme, although sometimes indeed you to use the remove_filter() beforehand, OR, like in this case, all you have to do is increase the priority of your added filter, in your case:

add_filter( 'excerpt_more', 'clientname_auto_excerpt_more', 11 );

That should do the trick. If not, increase the number.Thanks to this answer: