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

I can't seem to get my functions to work for changing the excerpt_more

Twenty Eleven parent theme filter .

I suspect it might actually be add_action( 'after_setup_theme', 'twentyeleven_setup' );

, but I even tried to remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' )

get rid of the Twenty Eleven feature and yet my features don't change anything ...

You can help?

Here's the complete code for functions.php:

http://pastie.org/3758708

Here's the functions I added to /mychildtheme/functions.php

function clientname_continue_reading_link() {
    return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Read more... <span class="meta-nav">&rarr;</span>', 'clientname' ) . '</a>';
}
function clientname_auto_excerpt_more( $more ) {
    return ' &hellip;' . clientname_continue_reading_link();
}
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more' );

      

Thank,

Wasps

+3


source to share


2 answers


Ok, so after a lot of frustrations, I found a solution to this (I thought "Kids Themes" was meant to speed things up !?). I believe this works because "after_theme_setup" is triggered after the parent theme has been installed, which means you can remove / override Twenty Eleven features at this point.

If I understood correctly, according to this documentation, the Child Theme is fired first, then the parent, and then the after_theme_setup bit of code in the child.php Child Theme 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 functions.php Child Theme 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

      

+8


source


Your own answer complicates things and really shouldn't be necessary. I couldn't explain why my answers are because I found this in another answer. But in any case, you can ALWAYS override functions from the parent theme in the child theme, although sometimes you do need to use remove_filter()

OR in advance, as 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 );

      



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

+4


source







All Articles