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! »' . '</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');
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.
If you don't want to write a new function and only want it to work in a specific area, you can also try the wp_trim_words() function combined with get_the_content()
Example:
<?php echo wp_trim_words(get_the_content(), 60) ?>
What the above will do is trim the words down on whatever returns from get_the_content() to the number of words you want (in this case, 60).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With