0

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 ?

1
  • .wp-caption-text{display: none;}
    – Howdy_McGee
    Dec 3, 2013 at 15:07

2 Answers 2

1

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

2
  • do_shortcode() is helpful, if you like it, that the shortcodes inside the content works after remove caption --> +1 for this answer.
    – bueltge
    Jan 1, 2015 at 20:13
  • 1
    Didn't worked for me in WP 4.2.5
    – testing
    Oct 13, 2015 at 20:39
0

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

1
  • Didn't worked for me in WP 4.2.5
    – testing
    Oct 13, 2015 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.