Answer a question

I am having an issue with the Remove_filter() .The remove filter works but not 100% , it wont remove the first 3 dots from Read More,and it wont replace the parent excerpt.

More clearly what I am trying to do, is to remove Read More and change it into [...] .

I want this to be done from child-theme.

Here are the screenshot exemple Before and After.

Parent theme functions.php code

    function new_excerpt_more($more) {
    global $post;
    return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More!   &raquo;'     . '</a>';
   }
    add_filter('excerpt_more', 'new_excerpt_more');

Child-theme functions.php code.

       function child_theme_setup() {
       // override parent theme's 'more' text for excerpts
       remove_filter( 'excerpt_more', 'new_excerpt_more' ); 

      }
     add_action( 'after_setup_theme', 'child_theme_setup' );
    // Replaces the excerpt "Read More" text by a link
     function new_excerpt($more) {
     global $post;
     return '<a class="moretag" href="'. get_permalink($post->ID) . '">[...]                      </a>';
      }
      add_filter('excerpt', 'new_excerpt');

Answers

You just need to update your code a little bit.

// Changing excerpt more
function new_excerpt_more($more) {
  global $post;
  remove_filter('excerpt_more', 'new_excerpt_more'); 
  return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . ' do whatever you want to update' . '</a>';
}
add_filter('excerpt_more','new_excerpt_more',11);

The default priority of a hook is 10. It is possible that the parent theme's hook gets added second, meaning both your hook and the parent hook have the same priority but the parent's came last therefore it doesn't reflects changes.

Logo

更多推荐