In my functions.php I have cooked up some functions to filter the attachment output code, when an attachment is sent to the editor.

function filter_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) { 
  $arr = get_attachments_and_widths_arr($id);
  return attachments_and_widths_to_html($arr, $id, $align, $caption, $alt);
add_filter('image_send_to_editor', 'filter_image_send_to_editor', 10, 9);

The return statement returns a string that contains pure html code and already has the caption text properly added to it. The problem is that because the Media Libary has some text in the 'Caption' field for that image and it automatically adds the [caption] shortcode around my html code after the above function returns. So I guess strip_shortcode() will not work in my case, since the string I am returning as filtered code does not yet have any shortcode, [caption] is added after the function returns.

How do I prevent this from happening?

EDIT: I know about this post, but I would like WP not to send any shortcode to the editor at all. The solution in that post removes the [caption] code when the post html is generated.

1 Answer 1


You can use the disable_captions filter, Just put it in your functions.php

add_filter( 'disable_captions', create_function('$a', 'return true;') );

Edit: As toscho pointed out this is a better solution!

add_filter( 'disable_captions', '__return_true' );


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.