WordPress.org

Support

Support » How-To and Troubleshooting » How To Remove Saved Caption From Only 1 Image

How To Remove Saved Caption From Only 1 Image

  • Hi;

    I have a bit of a conundrum. I want to be able to generate PHP code that will automatically remove the [caption ...........] …… [/caption] from the first image only without removing the image and leaving the caption of all other images in the content in place.

    I tried:

    $content = $post->post_content;
    $content = strip_shortcodes( $content );
    $content = apply_filters(‘the_content’, $content);
    echo $content;

    But that removes all images as well.

    I substituted $content = strip_shortcodes( $content ); with:

    $content = preg_replace(“/\[caption.*\[\/caption\]/”, ”, $content);

    but that doesn’t work.

    I need to save my content with the caption because I want it to appear on my mobile site. On my general website I don’t want the caption to be displayed but for the first image only.

    Any suggestions would be greatly appreciated.

    Thanks

    Lode

  • The topic ‘How To Remove Saved Caption From Only 1 Image’ is closed to new replies.
Skip to toolbar