• Paul Schreiber

    (@paulschreiber)


    I’d like to override twentyeleven_custom_excerpt_more(). Really, I just want to remove it. I tried adding remove_filter (in my child theme’s functions.php), per the instructions:

    remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );

    However, that has no effect. The “continue reading” text still appears.

    As a workaround, I added a filter to remove the text it inserts:

    function my_custom_excerpt_more( $output ) {
    	return str_replace("…", "", str_replace(twentyeleven_continue_reading_link(), "", $output));
    }
    add_filter( 'get_the_excerpt', 'my_custom_excerpt_more' );

    This is kludgy. How can I get remove_filter to work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The codex isn’t clear on this, but because the functions.php of the child theme is included before that of the parent, remove_filter would be called before the filter itself was actually added.

    I work around this by wrapping the remove_filter calls within a function and then calling that function from within the template, immediately before the_excerpt:

    Within functions.php:

    function remove_excerpt_filters() {
        remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
    }

    Within content.php (or other) template:

    remove_excerpt_filters();
    the_excerpt();

    I tried adding remove_filter (in my child theme’s functions.php), per the instructions

    I have just done this in a child theme’s after setup theme function.

    In the link the edited functions.php just showing changing ‘Continue Reading’ to ‘Read More’ for a twenty eleven child theme.

    https://pastebin.com/6kVvytCr

    Note: Added a line break so the ‘Read More’ starts a new line

    '<br/> …'

    @mark

    The codex isn’t clear on this, but because the functions.php of the child theme is included before that of the parent, remove_filter would be called before the filter itself was actually added.

    In the childs functions.php wrap any late calls in a function that is called after the parents functions.php is loaded, add_action('after_setup_theme','my_function_name');

    <?php
    /** This action will run the function below after theme setup */
    add_action( 'after_setup_theme', 'child_theme_setup' );
    
    /** This function will hold our new calls and over-rides */
    if ( !function_exists( 'child_theme_setup' ) ):
    function child_theme_setup() {
    	/** Add Code Here */
    
    }
    endif;

    EDIT:
    @mark
    Why are we posting on topics started 4 months ago? ;(

    HTH

    David

    David

    Thanks, that’s a more elegant way of doing it…I posted because I was searching on the same subject and found this. Figured I’d answer it…

    Hi Mark,
    No problem, it might help others searching for a solution!

    Cheers

    David

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Overriding twentyeleven_custom_excerpt_more()’ is closed to new replies.