GeneratePress, which im using as theme, has the following filter for arhive page post images. It adds a title tag to the a
element which im trying to remove.
I'm a bit unsure how to go about this filter, since i have only tried filter that are added to a variable after all functions are run.
The original function:
echo apply_filters( 'generate_featured_image_output', sprintf(
'<div class="post-image">
<a href="%1$s" title="%2$s">
%3$s
</a>
</div>',
esc_url( get_permalink() ),
the_title_attribute( 'echo=0' ),
get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), array('itemprop' => 'image') )
));
What i have tried:
add_filter( 'generate_featured_image_output' , 'remove_image_title_archive');
function remove_image_title_archive($text){
$text = preg_replace('/(title=".*")/', '', $text);
return $text;
}
Which does nothing.
I have also tried:
add_filter( 'generate_featured_image_output' , 'remove_image_title_archive');
function remove_image_title_archive($text){
return sprintf(
'<div class="post-image">
<a href="%1$s">
%2$s
</a>
</div>',
esc_url( get_permalink() ),
get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ), array('itemprop' => 'image') )
);
}
I have also tried setting the priority higher on both, but no effect.
Whats the procedure when filtering a sprintf
function like this one?
preg_replace
, you have mixed up your variable names ($test
vs$text
). Other than that, it doesn't look wrong to me, and sprintf just returns the string, so for all intents and purposes, it shouldn't matter to the filter if sprintf was used or a hardcoded string.$test
and$text
right after posting. Didn't change anything though. I also dont see why i shouldnt be able to return an entirely differentsprintf
function. Yet it doesn't work.