I have been using wp-caption for so long but for a template I am working on I want to delete this tag and only show the image, I used display:none; function but it does not show the image , any help ?
2 Answers
You'll need to use the img_caption_shortcode filter to do this. Pretty certain the alignment of the image (floating left/right) is part of the caption so you'll lose the ability to do that with this code.
function imageOnly($deprecated, $attr, $content = null)
{
return do_shortcode( $content );
}
add_filter( 'img_caption_shortcode', 'imageOnly', 10, 3 );
The do_shortcode is probably overkill.
I use something very similar to change the caption output to be responsive. Tested on WordPress 3.8.1
-
do_shortcode()
is helpful, if you like it, that the shortcodes inside the content works after remove caption --> +1 for this answer.– bueltgeJan 1, 2015 at 20:13 -
1
This code found on the WP Support forums (Can you remove captions from images?) worked for me:
function no_caption($deprecated, $attr, $content) { return $content; };
add_filter('img_caption_shortcode', 'no_caption', 10, 3);
Just drop it in your theme's functions.php
.wp-caption-text{display: none;}