• On my index page I have 300 char article summaries followed by ‘read more’, as per standard. However the char display adds the caption (bad enough) and to add insult to injury it outputs it in raw code, like this:

    [caption id="attachment_86" align="alignright" width="299" caption="Photo courtesy shopdivine"][/caption] Monique Leshman has been a favorite for ages owing to her boho meets glam designs and carefree aesthetic. I had the honor of meeting her and we had a great conversation. Here’s an excerpt fo

    The information is obtained by

    echo dp_clean($post->post_content, 300);

    I added a semi-fix by changing it to

    $rawContent = dp_clean($post->post_content, 300);
    $fixedContent = apply_filters(‘the_content’, $rawContent );
    echo $fixedContent;

    but the last [/caption] tag still shows up:

    [/caption]Monique Leshman has been a favorite for ages owing to her boho meets glam designs and carefree aesthetic. I had the honor of meeting her and we had a great conversation. Here’s an excerpt fo

    …and in some cases the actual caption does too, with space wasting padding around it. I don’t want any caption info on these summaries at all – how do I get rid of all caption info from post_content for the summaries, but still have captions in the main article?

Viewing 8 replies - 1 through 8 (of 8 total)
  • You could try using strip_shortcodes:

    $fixedContent = strip_shortcodes( dp_clean($post->post_content, 300));
    echo $fixedContent;
    Thread Starter manntis

    (@manntis)

    Thanks Esmi! I’m closer. Now it doesn’t show the padded caption at all, and removes the first part of the code, but leaves the last fragment without the first bracket ([):

    /caption]

    I could use a string parser to detect and remove that, I suppose, but it seems like a hamfisted fix when there should be some way to get the fist 300 chars of a post content without it including the caption parts AT ALL. Why take in information you don’t want, then do backflips to get rid of it? Not elegant.

    How about:

    $fixedContent = dp_clean( strip_shortcodes( $post->post_content ), 300));
    echo $fixedContent;
    Thread Starter manntis

    (@manntis)

    That did the trick! Thank you so much for your quick and practical help. It’s greatly appreciated.

    Thread Starter manntis

    (@manntis)

    quirm.net, hmm? ankh-morepork.net was taken or something? 😉

    LOL – well spotted! If you’re trying to come up with ideas and new scripts, what better name to use? I’m sure Leonard would approve. 🙂

    I am having the same problem as manntis, though I’m not sure where exactly I need to put the code that esmi has provided — can please someone enlighten me?

    diz

    Holy cow i fixed it…

    I don’t usually do this, but this was such a pain to fix it only seems right to at least explain how I resolved my issue.

    So, the “[caption]” shortcode was displaying on the index page of my blog — after HOURS of relentless searching and deactivating all of my plugins to no avail, I FINALLY came across this post.

    It explains that “the_excerpt Reloaded” plugin is the possible cause; When I deactivated this plugin it actually messed up my index page, so naturally I re-activated it straight away. After stumbling across this post (and thanks to cabraham posting such specific instructions) I simply located “the-excerpt-reloaded.php” file in my “\wp-content\plugins” directory and scrolled to line 102 — which was not exactly where I needed to drop the code (possibly because I have a newer version of “the_excerpt Reloaded” — cabraham’s post is 2 years old) but fortunately I was able to easily find “if($excerpt_length < 0)”, where he/she specified to drop the code before. Simple as that.

    I’m really relieved to have finally solved this, but I’m also really disappointed that there are so few posts on what Im sure is an extremely common problem, and for those posts that do exist I’m really disappointed that the instructions are so vague.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Zapping Captions’ is closed to new replies.