You code works where the function the_excerpt
is used. It does not work when get_the_excerpt
is used, which does not apply the the_excerpt
filter. It applies get_the_excerpt
instead.
Using get_the_excerpt
will cause the filter to apply to both the cases since the_excerpt()
uses get_the_excerpt()
.
Automatically generated excerpt content is a different thing since it is created by a filter on get_the_excerpt
that strips the markup.