0

I'm trying to remove a filter from within my plugin class. I need to remove the 'continue reading' link from the_excerpt. The base theme is the twenty ten theme and they are applying a filter twentyten_auto_excerpt_more. I cannot remove the filter, I assume because I'm within a class:

class MyAwesomeClass {

private static $instance;

public static function instance() {
    if ( !isset( self::$instance ) ) {
        self::$instance = new MyAwesomeClass;
        self::$instance->setup_actions_and_filters();
    }
    return self::$instance;
}

private function __construct() {}

public function setup_actions_and_filters() {
    add_filter( 'excerpt_more', array( $this, 'change_excerpt_more' ) );
}

public function change_excerpt_more( $excerpt ) {
    remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
    return '';
}

}

MyAwesomeClass::instance();

The filter I am trying to remove:

add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );

Is there a way of doing this?

0

The priority value has to match on remove_filter. I am guessing that it does not. Try:

remove_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );

Or find add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' and check the priority, then make it match.

  • There is no priority set, I've removed mine but it still doesn't work and a continue reading link appears... – keeg Aug 23 '13 at 15:33
0

It turns out that it was get_the_excerpt filter that needed removing, in either case it has to be done through after_setup_theme:

public function setup_actions_and_filters() {
    add_action( 'after_setup_theme', array( $this, 'run_plugin_setup' ) );
}

public function run_plugin_setup() {
    remove_all_filters( 'get_the_excerpt' );
}

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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