WordPress.org

Ready to get started?Download WordPress

Forums

How To Remove Saved Caption From Only 1 Image (1 post)

  1. hotinthenews
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic